CarpServiceException.fromMap constructor

CarpServiceException.fromMap(
  1. int httpStatusCode,
  2. Map<String, dynamic> map
)

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',
    );
  }
}