CarpServiceException.fromMap constructor
Create new CarpServiceException from a HTTP response httpStatusCode
and map
.
Implementation
factory CarpServiceException.fromMap(
int httpStatusCode, Map<String, dynamic> map) {
// we have two types of error messages - from CAWS and from NGINX
if (map.containsKey('path')) {
return CarpServiceException(
httpStatus: HTTPStatus(httpStatusCode),
message: map["message"].toString(),
path: map["path"].toString(),
);
} else if (map.containsKey('instance')) {
return CarpServiceException(
httpStatus: HTTPStatus(httpStatusCode),
message: map["detail"].toString(),
path: map["instance"].toString(),
);
} else {
return CarpServiceException(
httpStatus: HTTPStatus(httpStatusCode),
message: 'Unknown error',
);
}
}