Skip to content

Commit 4b937bb

Browse files
committed
api [nfc]: Add HttpException as base-class home for httpStatus field
1 parent cccf696 commit 4b937bb

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

lib/api/exception.dart

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ sealed class ApiRequestException implements Exception {
2828
String toString() => message;
2929
}
3030

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].
3235
class NetworkException extends ApiRequestException {
3336
/// The exception describing the underlying error.
3437
///
@@ -45,19 +48,26 @@ class NetworkException extends ApiRequestException {
4548
}
4649
}
4750

48-
/// An error returned through the Zulip server API.
51+
/// Some kind of [ApiRequestException] that came as an HTTP response.
4952
///
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 {
5655
/// The HTTP status code returned by the server.
5756
///
58-
/// This is always in the range 400..499.
57+
/// On [ZulipApiException], this is always in the range 400..499.
5958
final int httpStatus;
6059

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+
6171
/// The error's JSON data, if any, beyond the properties common to all errors.
6272
///
6373
/// This consists of the properties other than `result`, `code`, and `msg`.
@@ -67,8 +77,8 @@ class ZulipApiException extends ApiRequestException {
6777

6878
ZulipApiException({
6979
required super.routeName,
80+
required super.httpStatus,
7081
required this.code,
71-
required this.httpStatus,
7282
required this.data,
7383
required super.message,
7484
}) : assert(400 <= httpStatus && httpStatus <= 499);
@@ -91,17 +101,15 @@ class ZulipApiException extends ApiRequestException {
91101
/// This should always represent either some kind of operational issue
92102
/// on the server, or a bug in the server where its responses don't
93103
/// agree with the documented API.
94-
sealed class ServerException extends ApiRequestException {
95-
final int httpStatus;
96-
104+
sealed class ServerException extends HttpException {
97105
/// The response body, decoded as a JSON object.
98106
///
99107
/// This is null if the body could not be read, or was not a valid JSON object.
100108
final Map<String, dynamic>? data;
101109

102110
ServerException({
103111
required super.routeName,
104-
required this.httpStatus,
112+
required super.httpStatus,
105113
required this.data,
106114
required super.message,
107115
});

0 commit comments

Comments
 (0)