@@ -28,7 +28,10 @@ sealed class ApiRequestException implements Exception {
28
28
String toString () => message;
29
29
}
30
30
31
- /// A network-level error that prevented even getting an HTTP response.
31
+ /// A network-level error that prevented even getting an HTTP response
32
+ /// to some Zulip API network request.
33
+ ///
34
+ /// This is the antonym of [HttpException] .
32
35
class NetworkException extends ApiRequestException {
33
36
/// The exception describing the underlying error.
34
37
///
@@ -45,19 +48,26 @@ class NetworkException extends ApiRequestException {
45
48
}
46
49
}
47
50
48
- /// An error returned through the Zulip server API .
51
+ /// Some kind of [ApiRequestException] that came as an HTTP response .
49
52
///
50
- /// See API docs: https://zulip.com/api/rest-error-handling
51
- class ZulipApiException extends ApiRequestException {
52
-
53
- /// The Zulip API error code returned by the server.
54
- final String code;
55
-
53
+ /// This is the antonym of [NetworkException] .
54
+ sealed class HttpException extends ApiRequestException {
56
55
/// The HTTP status code returned by the server.
57
56
///
58
- /// This is always in the range 400..499.
57
+ /// On [ZulipApiException] , this is always in the range 400..499.
59
58
final int httpStatus;
60
59
60
+ HttpException ({required super .routeName, required this .httpStatus, required super .message});
61
+ }
62
+
63
+ /// An error returned through the Zulip server API,
64
+ /// and with a 4xx HTTP status code.
65
+ ///
66
+ /// See API docs: https://zulip.com/api/rest-error-handling
67
+ class ZulipApiException extends HttpException {
68
+ /// The Zulip API error code returned by the server.
69
+ final String code;
70
+
61
71
/// The error's JSON data, if any, beyond the properties common to all errors.
62
72
///
63
73
/// This consists of the properties other than `result` , `code` , and `msg` .
@@ -67,8 +77,8 @@ class ZulipApiException extends ApiRequestException {
67
77
68
78
ZulipApiException ({
69
79
required super .routeName,
80
+ required super .httpStatus,
70
81
required this .code,
71
- required this .httpStatus,
72
82
required this .data,
73
83
required super .message,
74
84
}) : assert (400 <= httpStatus && httpStatus <= 499 );
@@ -91,17 +101,15 @@ class ZulipApiException extends ApiRequestException {
91
101
/// This should always represent either some kind of operational issue
92
102
/// on the server, or a bug in the server where its responses don't
93
103
/// agree with the documented API.
94
- sealed class ServerException extends ApiRequestException {
95
- final int httpStatus;
96
-
104
+ sealed class ServerException extends HttpException {
97
105
/// The response body, decoded as a JSON object.
98
106
///
99
107
/// This is null if the body could not be read, or was not a valid JSON object.
100
108
final Map <String , dynamic >? data;
101
109
102
110
ServerException ({
103
111
required super .routeName,
104
- required this .httpStatus,
112
+ required super .httpStatus,
105
113
required this .data,
106
114
required super .message,
107
115
});
0 commit comments