Skip to content

Commit 7a7b443

Browse files
chrisbobbegnprice
authored andcommitted
api: Make RequestError explicitly abstract, in jsdoc
And choose a concrete subclass for the one place we were calling RequestError's constructor, which is really the Error class's constructor (with the one param `msg: mixed`) and so wasn't storing the passed `httpStatus` in its designated field. See: #5664 (comment)
1 parent deab4ad commit 7a7b443

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/api/apiErrors.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,15 @@ import { ZulipVersion } from '../utils/zulipVersion';
66
/**
77
* Some kind of error from a Zulip API network request.
88
*
9+
* This is an abstract class: every instance should be an instance of a
10+
* subclass. Rather than construct it directly, use a subclass's
11+
* constructor.
12+
*
913
* See subclasses: {@link ApiError}, {@link NetworkError}, {@link ServerError}.
1014
*/
15+
// For why we just say "abstract" in the jsdoc without doing anything static
16+
// or dynamic to enforce that, see:
17+
// https://github.com/zulip/zulip-mobile/pull/5664#issuecomment-1433918758
1118
export class RequestError extends ExtendableError {
1219
/** The HTTP status code in the response, if any. */
1320
+httpStatus: number | void;

src/api/fetchServerEmojiData.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { networkActivityStart, networkActivityStop } from '../utils/networkActiv
33
import {
44
MalformedResponseError,
55
NetworkError,
6-
RequestError,
76
Server5xxError,
7+
ServerError,
88
UnexpectedHttpStatusError,
99
} from './apiErrors';
1010
import type { ServerEmojiData } from './modelTypes';
@@ -70,15 +70,15 @@ export default async (emojiDataUrl: URL): Promise<ServerEmojiData> => {
7070

7171
const httpStatus = response.status;
7272
if (httpStatus >= 400 && httpStatus <= 499) {
73-
// Client error…?
73+
// A client error, supposedly.
7474
//
7575
// If 404, maybe we had the wrong idea of what URL to request (unlikely,
7676
// but would be a client error). Or maybe the server failed to get
7777
// provisioned with the JSON file at the promised URL (a server error).
7878
//
7979
// Don't bother trying to make an ApiError by parsing JSON for `code`,
8080
// `msg`, or `result`; this endpoint doesn't give them.
81-
throw new RequestError(httpStatus);
81+
throw new ServerError('Could not get server emoji data', httpStatus);
8282
} else if (httpStatus >= 500 && httpStatus <= 599) {
8383
throw new Server5xxError(httpStatus);
8484
} else if (httpStatus <= 199 || (httpStatus >= 300 && httpStatus <= 399) || httpStatus >= 600) {

0 commit comments

Comments
 (0)