BaseError.fromApiException constructor

BaseError.fromApiException(
  1. ApiException exception
)

Converts ApiException to BaseError

Implementation

factory BaseError.fromApiException(ApiException exception) {
  return switch (exception) {
    NetworkException(
      :final message,
      :final stackTrace,
    ) =>
      NetworkError(
        message: message,
        stackTrace: stackTrace,
      ),
    UnAuthorizedException(
      :final message,
      :final stackTrace,
    ) =>
      UnAuthorizedError(
        message: message,
        stackTrace: stackTrace,
      ),
    BadRequestException(
      :final message,
      :final stackTrace,
      :final errors,
    ) ||
    ValidationException(
      :final message,
      :final stackTrace,
      :final errors,
    ) =>
      ValidationError(
        message: message,
        stackTrace: stackTrace,
        errors: errors,
      ),
    _ => ServerError(
        message: exception.message,
        stackTrace: exception.stackTrace,
        statusCode: exception.code,
      ),
  };
}