Skip to content

Commit b87a3b0

Browse files
authored
💬 Overrides InterceptorState.toString() (#2247)
Resolves #2226
1 parent 3eb2f4e commit b87a3b0

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

dio/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ See the [Migration Guide][] for the complete breaking changes list.**
99
- Add constructor for `DioExceptionType.badCertificate`.
1010
- Create type alias `DioMediaType` for `http_parser`'s `MediaType`.
1111
- Fix the type conversion regression when using `MultipartFile.fromBytes`.
12+
- Improves `InterceptorState.toString()`.
1213

1314
## 5.4.3+1
1415

dio/lib/src/interceptor.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
part of 'dio_mixin.dart';
22

3-
/// @nodoc
3+
/// The result type after handled by the interceptor.
44
enum InterceptorResultType {
55
next,
66
resolve,
@@ -10,12 +10,14 @@ enum InterceptorResultType {
1010
}
1111

1212
/// Used to pass state between interceptors.
13-
/// @nodoc
1413
class InterceptorState<T> {
1514
const InterceptorState(this.data, [this.type = InterceptorResultType.next]);
1615

1716
final T data;
1817
final InterceptorResultType type;
18+
19+
@override
20+
String toString() => 'InterceptorState<$T>(type: $type, data: $data)';
1921
}
2022

2123
abstract class _BaseHandler {

dio/test/interceptor_test.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'dart:async';
22

33
import 'package:dio/dio.dart';
4+
import 'package:dio/src/dio_mixin.dart';
45
import 'package:dio/src/interceptors/imply_content_type.dart';
56
import 'package:test/test.dart';
67

@@ -85,6 +86,20 @@ void main() {
8586
);
8687
});
8788

89+
group('InterceptorState', () {
90+
test('toString()', () {
91+
final data = DioException(requestOptions: RequestOptions());
92+
final state = InterceptorState<DioException>(data);
93+
expect(
94+
state.toString(),
95+
'InterceptorState<DioException>('
96+
'type: InterceptorResultType.next, '
97+
'data: DioException [unknown]: null'
98+
')',
99+
);
100+
});
101+
});
102+
88103
group('Request Interceptor', () {
89104
test('interceptor chain', () async {
90105
final dio = Dio();

0 commit comments

Comments
 (0)