ApiRequestError constructor

ApiRequestError(
  1. dynamic apiError
)

Implementation

ApiRequestError(dynamic apiError) {
  if (apiError is DioError) {
    this.requestOptions = apiError.requestOptions;
    this.response = apiError.response;
    this.error = apiError.error;
    this.statusCode = apiError.response?.statusCode;
    message = (error?.toString() ?? '');
    if (this.response?.data is Map) {
      if (this.response?.data['errors'] is Map) {
        this.errors = this.response?.data['errors'];
      }
      if (this.response?.data['message'] != null) {
        message = this.response?.data['message'];
      }
    }
  } else if (apiError is Error) {
    this.message = apiError.toString();
    this._stackTrace = apiError.stackTrace;
    error = apiError;
  } else {
    throw Exception('Unknown Error');
  }
}