Skip to content

Commit 6caa937

Browse files
committed
api [nfc]: Assert ZulipApiException.data is free of redundant keys
These three keys appear in the server's JSON for error responses, but get pulled out into their own dedicated fields in ZulipApiException. (See the field's doc, and the constructor's one non-test call site.) The assertion is useful for tests, for keeping test data realistic. Fix the two test cases that had missed this nuance.
1 parent a055486 commit 6caa937

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

lib/api/exception.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,10 @@ class ZulipApiException extends HttpException {
8181
required this.code,
8282
required this.data,
8383
required super.message,
84-
}) : assert(400 <= httpStatus && httpStatus <= 499);
84+
}) : assert(400 <= httpStatus && httpStatus <= 499),
85+
assert(!data.containsKey('result')
86+
&& !data.containsKey('code')
87+
&& !data.containsKey('msg'));
8588

8689
@override
8790
String toString() {

test/model/actions_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ void main() {
105105
final exception = ZulipApiException(
106106
httpStatus: 401,
107107
code: 'UNAUTHORIZED',
108-
data: {"result": "error", "msg": "Invalid API key", "code": "UNAUTHORIZED"},
108+
data: {},
109109
routeName: 'removeEtcEtcToken',
110110
message: 'Invalid API key',
111111
);
@@ -174,7 +174,7 @@ void main() {
174174
..prepare(exception: ZulipApiException(
175175
httpStatus: 401,
176176
code: 'UNAUTHORIZED',
177-
data: {"result": "error", "msg": "Invalid API key", "code": "UNAUTHORIZED"},
177+
data: {},
178178
routeName: 'removeEtcEtcToken',
179179
message: 'Invalid API key',
180180
));

0 commit comments

Comments
 (0)