status method

ResponseStatus status()

status returns the status code and reason phrase of the response as a ResponseStatus object.

If the response is an Exception, the status code will be 500 and the reason phrase will be the exception message.

If the response is not an Exception or http.BaseResponse, the status code will be 500 and the reason phrase will be "Unknown Error".

Implementation

ResponseStatus status() {
  if (_status != null) return _status!;
  if (result is http.BaseResponse) {
    var result = this.result as http.BaseResponse;
    _status = ResponseStatus(result.statusCode, result.reasonPhrase);
  } else if (result is Exception) {
    _status = ResponseStatus(500, result.toString());
  } else {
    _status = ResponseStatus(500, "Unknown Error");
  }
  return _status!;
}