failure function

AngelHttpException failure(
  1. Response response, {
  2. dynamic error,
  3. String? message,
  4. StackTrace? stack,
})

Implementation

AngelHttpException failure(Response response,
    {error, String? message, StackTrace? stack}) {
  try {
    var v = json.decode(response.body);

    if (v is Map && (v['is_error'] == true) || v['isError'] == true) {
      return AngelHttpException.fromMap(v as Map);
    } else {
      return AngelHttpException(
          message: message ??
              'Unhandled exception while connecting to Angel backend.',
          statusCode: response.statusCode,
          stackTrace: stack);
    }
  } catch (e, st) {
    return AngelHttpException(
        message: message ??
            'Angel backend did not return JSON - an error likely occurred.',
        statusCode: response.statusCode,
        stackTrace: stack ?? st);
  }
}