decodeRestResponse function

Map<String, dynamic> decodeRestResponse(
  1. Response response
)

The body of a 2xx response; throws a RestApiException otherwise.

Implementation

Map<String, dynamic> decodeRestResponse(Response response) {
  final Map<String, dynamic> body = decodeRestBody(response.body);
  final int status = response.statusCode;

  if (status >= 200 && status < 300) return body;
  if (status == 401) throw RestUnauthorizedException(body: body);
  if (status == 403) {
    final ({String? message, String? permission}) denial =
        parsePermissionDenial(body);
    throw RestForbiddenException(
      body: body,
      message: denial.message,
      permission: denial.permission,
    );
  }
  throw RestApiException(statusCode: status, body: body);
}