1 | | | import 'package:cancelation_token/cancelation_token.dart'; |
2 | | | import 'package:meta/meta.dart'; |
3 | | |
|
4 | | | import '_well_known_exceptions.dart'; |
5 | | | import 'squadron_canceled_exceptions.dart'; |
6 | | | import 'squadron_exception.dart'; |
7 | | | import 'squadron_timeout_exception.dart'; |
8 | | |
|
9 | | | class SquadronCanceledException extends SquadronException |
10 | | | implements CanceledException { |
11 | | 6 | SquadronCanceledException( |
12 | | | this.tokenId, String message, StackTrace? stackTrace) |
13 | | 6 | : super.init(message, stackTrace); |
14 | | |
|
15 | | 5 | factory SquadronCanceledException.from(String tokenId, CanceledException ex, |
16 | | | [StackTrace? stackTrace]) { |
17 | | 5 | if (ex is TimeoutCanceledException) { |
18 | | 3 | return SquadronTimeoutException( |
19 | | 4 | tokenId, ex.message, ex.duration, ex.stackTrace); |
20 | | 4 | } else if (ex is CanceledExceptions) { |
21 | | 2 | return SquadronCanceledExceptions( |
22 | | | tokenId, |
23 | | 3 | ex.innerExceptions.map( |
24 | | 4 | (e) => SquadronCanceledException.from(tokenId, e, e.stackTrace), |
25 | | | ), |
26 | | | ); |
27 | | | } else { |
28 | | 11 | return SquadronCanceledException(tokenId, ex.message, ex.stackTrace); |
29 | | | } |
30 | | 2 | } |
31 | | |
|
32 | | | final String tokenId; |
33 | | |
|
34 | | 3 | @override |
35 | | 8 | List serialize() => List.unmodifiable([ |
36 | | | $canceledExceptionType, |
37 | | 5 | tokenId, |
38 | | 5 | message, |
39 | | 8 | stackTrace?.toString(), |
40 | | 2 | ]); |
41 | | | } |
42 | | |
|
43 | | | const _$type = 0; |
44 | | | const _$tokenId = 1; |
45 | | | const _$message = 2; |
46 | | | const _$stackTrace = 3; |
47 | | |
|
48 | | | @internal |
49 | | | extension SquadronCanceledExceptionExt on SquadronCanceledException { |
50 | | 5 | static SquadronCanceledException? deserialize(List? props) { |
51 | | 2 | if (props == null) return null; |
52 | | 5 | switch (props[_$type]) { |
53 | | 3 | case $canceledExceptionType: |
54 | | 5 | return SquadronCanceledException( |
55 | | 5 | props[_$tokenId], |
56 | | 5 | props[_$message], |
57 | | 8 | SquadronException.loadStackTrace(props[_$stackTrace]), |
58 | | | ); |
59 | | 1 | case $canceledExceptionsType: |
60 | | 1 | return SquadronCanceledExceptionsExt.deserialize(props); |
61 | | 1 | case $timeoutExceptionType: |
62 | | 1 | return SquadronTimeoutExceptionExt.deserialize(props); |
63 | | | default: |
64 | | 0 | return null; |
65 | | | } |
66 | | 2 | } |
67 | | | } |