extractItemFromJsonResponse method

Json extractItemFromJsonResponse(
  1. JsonApiResultBody body
)

Overrideable hook to extract the raw item payloads out of the response body.

Implementation

Json extractItemFromJsonResponse(JsonApiResultBody body) {
  switch (body.data) {
    case Map():
      return body.data as Json;
    case List():
      final dataList = body.data as List;
      if (dataList.length != 1) {
        _log.severe(
          'Unexpectedly received ${dataList.length} items in detail response',
        );
      }
      return dataList.first as Json;
    case _:
      throw Exception(
        'Unexpected data type: ${body.data.runtimeType} in detail response',
      );
  }
}