parseErrorDetails method

TrayRequestError parseErrorDetails(
  1. TrayRequest request,
  2. Response response,
  3. Map<String, dynamic> errorBodyJson, {
  4. Map<String, dynamic>? debugInfo,
})

This method is used to parse the output of failing requests we need a way to retrieve the error message and error details if you don't use the default message and errors key, in your api, you can overwrite the mapping here and make sure everything is passed correctly

Implementation

TrayRequestError parseErrorDetails(
  TrayRequest request,
  Response response,
  Map<String, dynamic> errorBodyJson, {
  Map<String, dynamic>? debugInfo,
}) {
  return TrayRequestError(
    message:
        errorBodyJson['message'] ?? 'Failed to load request ${request.url}!',
    errors: errorBodyJson['errors'] ?? [],
    statusCode: response.statusCode,
    debugInfo: debugInfo,
  );
}