File tree Expand file tree Collapse file tree 1 file changed +16
-9
lines changed Expand file tree Collapse file tree 1 file changed +16
-9
lines changed Original file line number Diff line number Diff line change
1
+ import 'dart:developer' as dev;
2
+
1
3
import 'package:flutter_deriv_api/api/models/base_exception_model.dart' ;
2
4
3
- /// Base exception class
5
+ /// Base exception class for all API exceptions.
4
6
class APIBaseException implements Exception {
5
7
/// Initializes
6
8
APIBaseException ({
7
9
required this .baseExceptionModel,
8
10
});
9
11
10
- /// Exception code
12
+ /// Exception code and message model from API response.
11
13
final BaseExceptionModel ? baseExceptionModel;
12
14
13
- /// The exception's message
14
- String ? get message => baseExceptionModel! .message;
15
+ /// The exception's message (if any).
16
+ String ? get message => baseExceptionModel? .message;
15
17
16
- /// The exception's code
17
- String ? get code => baseExceptionModel! .code;
18
+ /// The exception's code (if any).
19
+ String ? get code => baseExceptionModel? .code;
18
20
19
21
/// The exception's details.
20
- Map <String , dynamic >? get details => baseExceptionModel! .details;
22
+ Map <String , dynamic >? get details => baseExceptionModel? .details;
21
23
22
24
@override
23
- String toString () =>
24
- '$runtimeType (code: ${baseExceptionModel !.code }, message: ${baseExceptionModel !.message })' ;
25
+ String toString () {
26
+ dev.log (
27
+ '$runtimeType (code: $code , message: $message )' ,
28
+ );
29
+
30
+ return message ?? '$runtimeType : API unknown error.' ;
31
+ }
25
32
}
You can’t perform that action at this time.
0 commit comments