NorbixError.fromHttp constructor

NorbixError.fromHttp({
  1. required int status,
  2. required String message,
  3. required String code,
  4. Map<String, dynamic> details = const {},
  5. List<NorbixErrorItem> errors = const [],
  6. Object? body,
})

Construct the right typed subclass from an HTTP response. Used by the transport — you usually do not call this directly.

Implementation

factory NorbixError.fromHttp({
  required int status,
  required String message,
  required String code,
  Map<String, dynamic> details = const {},
  List<NorbixErrorItem> errors = const [],
  Object? body,
}) {
  if (status == 401 || status == 403) {
    return NorbixAuthError(
        message: message,
        code: code,
        status: status,
        details: details,
        errors: errors,
        body: body);
  }
  if (status == 404) {
    return NorbixNotFoundError(
        message: message,
        code: code,
        status: status,
        details: details,
        errors: errors,
        body: body);
  }
  if (status == 429) {
    return NorbixRateLimitError(
        message: message,
        code: code,
        status: status,
        details: details,
        errors: errors,
        body: body);
  }
  if (status >= 500) {
    return NorbixServerError(
        message: message,
        code: code,
        status: status,
        details: details,
        errors: errors,
        body: body);
  }
  if (status >= 400) {
    return NorbixClientError(
        message: message,
        code: code,
        status: status,
        details: details,
        errors: errors,
        body: body);
  }
  return NorbixError(
      message: message,
      code: code,
      status: status,
      details: details,
      errors: errors,
      body: body);
}