Skip to content

Commit

Permalink
[dio] Revert changes to CancelToken.cancel behavior (cfug#1769)
Browse files Browse the repository at this point in the history
### New Pull Request Checklist

- [x] I have read the
[Documentation](https://pub.dev/documentation/dio/latest/)
- [x] I have searched for a similar pull request in the
[project](https://github.com/cfug/dio/pulls) and found none
- [x] I have updated this branch with the latest `main` branch to avoid
conflicts (via merge from master or rebase)
- [x] I have added the required tests to prove the fix/feature I'm
adding
- [x] I have updated the documentation (if necessary)
- [x] I have run the tests without failures
- [x] I have updated the `CHANGELOG.md` in the corresponding package

### Additional context and info (if any)

Fixes cfug#1765
  • Loading branch information
kuhnroyal authored Mar 28, 2023
1 parent f11f5f0 commit ae90d7d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 11 deletions.
4 changes: 3 additions & 1 deletion dio/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

## Unreleased

*None.*
- Revert changes to `CancelToken.cancel()` behavior, as a result the `DioError`
provided by the `CancelToken.cancelError` does not contain useful information
when the token was not used with a request.

## 5.1.0

Expand Down
7 changes: 1 addition & 6 deletions dio/lib/src/cancel_token.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,8 @@ class CancelToken {

/// Cancel the request with the given [reason].
void cancel([Object? reason]) {
if (requestOptions == null) {
throw StateError(
'CancelToken was canceled before being used in a request.',
);
}
_cancelError = DioError.requestCancelled(
requestOptions: requestOptions!,
requestOptions: requestOptions ?? RequestOptions(),
reason: reason,
stackTrace: StackTrace.current,
);
Expand Down
6 changes: 2 additions & 4 deletions dio/test/cancel_token_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@ void main() {
token.cancel(reason);
});

test('cancel without use throws StateError', () async {
final token = CancelToken();

expect(() => token.cancel(), throwsStateError);
test('cancel without use does not throw (#1765)', () async {
CancelToken().cancel();
});
});
}

0 comments on commit ae90d7d

Please sign in to comment.