decorateResponse function

Response decorateResponse(
  1. Response response
)

Implementation

http.Response decorateResponse(http.Response response) {
  // debugPrint('req: ${response.request!.url} ${response.statusCode}');
  final code = response.statusCode;
  final body = response.body;

  switch (code) {
    case HttpStatus.internalServerError:
    case HttpStatus.badGateway:
    case HttpStatus.unauthorized:
    case HttpStatus.badRequest:
    case HttpStatus.notFound:
    case HttpStatus.gatewayTimeout:
      debugPrint("Error: $body");
      throw RequestException(
        message: 'Hubo un problema - Timeout',
        status: code,
      );
    case HttpStatus.forbidden:
      debugPrint("Error: $body");
      throw RequestException(
        message: 'Hubo un problema - Forbidden',
        status: code,
      );
    default:
      return response;
  }
}