Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I can't return my own errors class in onError interceptor #2209

Closed
andrefedev opened this issue May 5, 2024 · 1 comment
Closed

I can't return my own errors class in onError interceptor #2209

andrefedev opened this issue May 5, 2024 · 1 comment
Labels
s: feature This issue indicates a feature request

Comments

@andrefedev
Copy link

andrefedev commented May 5, 2024

Request Statement

So, I don't want to have to extend DioException. I want to be able to use interceptors to handle DioException errors with my own error class that extends Exception without dying trying. But it definitely doesn't work. There is no information about this in the documentation. I have a package that is an api and I don't want the applications that use it to have to install Dio just to handle DioException or in the worst case if I changed to Dio for whatever we would have to make a big change.

Solution Brainstorm

// ##########################
// # ErrorHandle Middleware #
// ##########################

interceptors.add(
  InterceptorsWrapper(
    onError: (DioException error, ErrorInterceptorHandler handler) {
      switch (error.type) {
        case DioExceptionType.badResponse:
          // throw ApiException.fromBadResponse(response);
          return handler.reject(_handleBadResponse(error));
        case DioExceptionType.connectionError:
          // // throw ApiException.fromBadResponse(response);
          return handler.reject(_handleConnectionError):

        default:
          return handler.reject(error);
      }
    },
  ),
);
@andrefedev andrefedev added the s: feature This issue indicates a feature request label May 5, 2024
@kuhnroyal
Copy link
Member

Thanks, duplicate of #1950 - please follow up there.

@kuhnroyal kuhnroyal closed this as not planned Won't fix, can't repro, duplicate, stale May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
s: feature This issue indicates a feature request
Projects
None yet
Development

No branches or pull requests

2 participants