-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
feat(dio): propagate custom exception types from interceptors (#1950) #2514
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
d63e800
c5c0752
b3e4486
74b0cc2
2754e17
ab0bc23
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -97,6 +97,26 @@ class RequestInterceptorHandler extends _BaseHandler { | |
| ); | ||
| _processNextInQueue?.call(); | ||
| } | ||
|
|
||
| /// Rejects the request with a [DioException.custom] wrapping [error] and | ||
| /// signals the pipeline to rethrow [error] verbatim to the caller of the | ||
| /// request method, preserving its runtime type. | ||
| /// | ||
| /// Use when you want callers to `on MyException catch (e)` directly, | ||
| /// rather than `on DioException catch (e) { final inner = e.error; ... }`. | ||
| /// See [DioException.custom] for details. | ||
| /// | ||
| /// Resolves https://github.com/cfug/dio/issues/1950. | ||
| void rejectCustomError( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would probably go with just
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done — renamed to |
||
| Object error, | ||
| RequestOptions requestOptions, [ | ||
| bool callFollowingErrorInterceptor = false, | ||
| ]) { | ||
| reject( | ||
| DioException.custom(error, requestOptions: requestOptions), | ||
| callFollowingErrorInterceptor, | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| /// The handler for interceptors to handle after respond. | ||
|
|
@@ -148,6 +168,18 @@ class ResponseInterceptorHandler extends _BaseHandler { | |
| ); | ||
| _processNextInQueue?.call(); | ||
| } | ||
|
|
||
| /// See [RequestInterceptorHandler.rejectCustomError]. | ||
| void rejectCustomError( | ||
| Object error, | ||
| RequestOptions requestOptions, [ | ||
| bool callFollowingErrorInterceptor = false, | ||
| ]) { | ||
| reject( | ||
| DioException.custom(error, requestOptions: requestOptions), | ||
| callFollowingErrorInterceptor, | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| /// The handler for interceptors to handle error occurred during the request. | ||
|
|
@@ -186,6 +218,14 @@ class ErrorInterceptorHandler extends _BaseHandler { | |
| ); | ||
| _processNextInQueue?.call(); | ||
| } | ||
|
|
||
| /// See [RequestInterceptorHandler.rejectCustomError]. | ||
| void rejectCustomError( | ||
| Object error, | ||
| RequestOptions requestOptions, | ||
| ) { | ||
| reject(DioException.custom(error, requestOptions: requestOptions)); | ||
| } | ||
| } | ||
|
|
||
| /// [Interceptor] helps to deal with [RequestOptions], [Response], | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isCustom?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done — renamed the field (plus the constructor and
copyWithparams) toisCustom, matching theDioException.customfactory. Tests + README updated.