handelAPIError static method
void
handelAPIError(
{ - required int desireStatusCode,
- required Response response,
})
Implementation
static void handelAPIError({
required int desireStatusCode,
required Response response,
}) {
if (desireStatusCode == response.statusCode) {
return;
}
try {
ErrorType _errorType = errorTypeFromStatusCode(response.statusCode);
if (_errorType == ErrorType.unknown) {
var jsonData = json.decode(response.body);
var errorMsg = jsonData['error'];
var errorMsg2 = jsonData['message'];
throw UnknownException(
message: errorMsg ?? errorMsg2,
);
} else {
throw errorResponse(_errorType);
}
} on AppException {
rethrow;
} catch (e) {
throw UnknownException(
message: e.toString(),
);
}
}