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

Improve default parameter naming for Interceptor #2047

Merged
merged 4 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions dio/README-ZH.md
Original file line number Diff line number Diff line change
Expand Up @@ -447,9 +447,9 @@ dio.interceptors.add(
// 如果你想终止请求并触发一个错误,你可以使用 `handler.reject(error)`。
return handler.next(response);
},
onError: (DioException e, ErrorInterceptorHandler handler) {
onError: (DioException err, ErrorInterceptorHandler handler) {
// 如果你想完成请求并返回一些自定义数据,你可以使用 `handler.resolve(response)`。
return handler.next(e);
return handler.next(err);
},
),
);
Expand Down
4 changes: 2 additions & 2 deletions dio/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -450,11 +450,11 @@ dio.interceptors.add(
// you can reject a `DioException` object using `handler.reject(dioError)`.
return handler.next(response);
},
onError: (DioException e, ErrorInterceptorHandler handler) {
onError: (DioException err, ErrorInterceptorHandler handler) {
// Do something with response error.
// If you want to resolve the request with some custom data,
// you can resolve a `Response` object using `handler.resolve(response)`.
return handler.next(e);
return handler.next(err);
},
),
);
Expand Down
4 changes: 2 additions & 2 deletions dio/lib/src/interceptor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,13 @@ typedef InterceptorSendCallback = void Function(

/// The signature of [Interceptor.onResponse].
typedef InterceptorSuccessCallback = void Function(
Response<dynamic> e,
Response<dynamic> response,
ResponseInterceptorHandler handler,
);

/// The signature of [Interceptor.onError].
typedef InterceptorErrorCallback = void Function(
DioException e,
DioException err,
AlexV525 marked this conversation as resolved.
Show resolved Hide resolved
ErrorInterceptorHandler handler,
);

Expand Down
30 changes: 15 additions & 15 deletions dio/test/interceptor_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -421,34 +421,34 @@ void main() {
response.data = response.data['data'];
handler.next(response);
},
onError: (DioException e, ErrorInterceptorHandler handler) {
if (e.response?.requestOptions != null) {
switch (e.response!.requestOptions.path) {
onError: (DioException err, ErrorInterceptorHandler handler) {
if (err.response?.requestOptions != null) {
switch (err.response!.requestOptions.path) {
case urlNotFound:
return handler.next(e);
return handler.next(err);
case urlNotFound1:
return handler.resolve(
Response(
requestOptions: e.requestOptions,
requestOptions: err.requestOptions,
data: 'fake data',
),
);
case urlNotFound2:
return handler.resolve(
Response(
data: 'fake data',
requestOptions: e.requestOptions,
requestOptions: err.requestOptions,
),
);
case urlNotFound3:
return handler.next(
e.copyWith(
error: 'custom error info [${e.response!.statusCode}]',
err.copyWith(
error: 'custom error info [${err.response!.statusCode}]',
),
);
}
}
handler.next(e);
handler.next(err);
},
),
);
Expand Down Expand Up @@ -514,17 +514,17 @@ void main() {
..options.baseUrl = MockAdapter.mockBase
..interceptors.add(
InterceptorsWrapper(
onError: (DioException e, ErrorInterceptorHandler handler) {
iError = e;
handler.next(e);
onError: (DioException err, ErrorInterceptorHandler handler) {
iError = err;
handler.next(err);
},
),
)
..interceptors.add(
QueuedInterceptorsWrapper(
onError: (DioException e, ErrorInterceptorHandler handler) {
qError = e;
handler.next(e);
onError: (DioException err, ErrorInterceptorHandler handler) {
qError = err;
handler.next(err);
},
),
);
Expand Down
18 changes: 9 additions & 9 deletions example/lib/response_interceptor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,37 +15,37 @@ void main() async {
response.data = json.decode(response.data['data']);
handler.next(response);
},
onError: (DioException e, handler) {
if (e.response != null) {
switch (e.response!.requestOptions.path) {
onError: (DioException err, handler) {
if (err.response != null) {
switch (err.response!.requestOptions.path) {
case urlNotFound:
return handler.next(e);
return handler.next(err);
case urlNotFound1:
handler.resolve(
Response(
requestOptions: e.requestOptions,
requestOptions: err.requestOptions,
data: 'fake data',
),
);
break;
case urlNotFound2:
handler.resolve(
Response(
requestOptions: e.requestOptions,
requestOptions: err.requestOptions,
data: 'fake data',
),
);
break;
case urlNotFound3:
handler.next(
e.copyWith(
error: 'custom error info [${e.response!.statusCode}]',
err.copyWith(
error: 'custom error info [${err.response!.statusCode}]',
),
);
break;
}
} else {
handler.next(e);
handler.next(err);
}
},
),
Expand Down