AngelHttpException.fromMap constructor

AngelHttpException.fromMap(
  1. Map data, {
  2. int fallbackStatusCode = 500,
})

Uses fallbackStatusCode when data has no valid status code, e.g. the status of the HTTP response it came from; 500 if that is not valid either.

Implementation

factory AngelHttpException.fromMap(Map data, {int fallbackStatusCode = 500}) {
  var statusCode =
      _parseStatusCode(data['status_code']) ??
      _parseStatusCode(data['statusCode']) ??
      _parseStatusCode(fallbackStatusCode) ??
      500;
  return AngelHttpException(
    statusCode: statusCode,
    // Without a message, one that matches the status code.
    message:
        data['message']?.toString() ??
        (statusCode == 500 ? _defaultMessage : '$statusCode'),
    errors: data['errors'] is Iterable
        ? ((data['errors'] as Iterable).map((x) => x.toString()).toList())
        : <String>[],
  );
}