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

Developer should throw custom exception in interceptor #1950

Open
WutangNailao opened this issue Sep 1, 2023 · 9 comments
Open

Developer should throw custom exception in interceptor #1950

WutangNailao opened this issue Sep 1, 2023 · 9 comments
Labels
e: PR welcomed p: dio Targeting `dio` package s: feature This issue indicates a feature request

Comments

@WutangNailao
Copy link

Request Statement

When i write a interceptor class extends Interceptor, in some case, i wish throw some exception to tell the developer some thing went wrong. so i throw a custom exception in override function 'onResponse', but this exception was catched by DioException, and this exception can not tell me more infomation about this error.

image
image

So, i wish this will be supported

Solution Brainstorm

No response

@WutangNailao WutangNailao added the s: feature This issue indicates a feature request label Sep 1, 2023
@ueman
Copy link
Contributor

ueman commented Sep 1, 2023

This makes a lot of sense.

I think we either should properly wrap the exception, or we shouldn't wrap it at all.

@kuhnroyal
Copy link
Member

I think we do.

Just from looking at the screens, the reported exception probably originated at the jsonDecode.

@AlexV525
Copy link
Member

These (#1949) are quite similar which requires a nicer first-look regarding the exception.

@kuhnroyal
Copy link
Member

Adding request information to the exception is one thing. Figuring out a sensible way to convert arbitrary exceptions/objects into strings is another. Any ideas for this? We call toString() on the inner error but we don't always pass a message to the DioException - that is why it says [unknown]: null.

@SpeedReach
Copy link
Contributor

DioException has a error field, this is probably what you're looking for?

/// The original error/exception object;
/// It's usually not null when `type` is [DioExceptionType.unknown].
final Object? error;

@AlexV525
Copy link
Member

Based on the above comments, the root cause of the exception is the JSON fails to be decoded before it reaches your exception, so a FormatException was thrown. Otherwise, it would be DioException(APIException).

Closing as it's working as intended.

@AlexV525 AlexV525 closed this as not planned Won't fix, can't repro, duplicate, stale Oct 14, 2023
@AlexV525 AlexV525 added i: wontfix This will not be worked on and removed s: feature This issue indicates a feature request labels Oct 14, 2023
@WutangNailao
Copy link
Author

it's my wrong, i show a wrong example.
this is a good example i think for my issue.
image
image

when i get a response with code 401, i throw a apiexception, in the terminal, i see which i throwed apiexception, but it wrapped with dioException, so i can't not catch this error exactly next time.

@AlexV525 AlexV525 reopened this Oct 24, 2023
@AlexV525 AlexV525 added s: feature This issue indicates a feature request p: dio Targeting `dio` package and removed i: wontfix This will not be worked on labels Oct 24, 2023
@kuhnroyal
Copy link
Member

Not sure how we can achieve that other than the developer registering custom types somewhere.

@mietl
Copy link

mietl commented Aug 17, 2024

Has there been no progress on this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
e: PR welcomed p: dio Targeting `dio` package s: feature This issue indicates a feature request
Projects
None yet
Development

No branches or pull requests

6 participants