Skip to content

Commit 3d1c974

Browse files
committed
Add comment about handling of resposeFor errors
1 parent 38ccc73 commit 3d1c974

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/webServiceClient.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,21 @@ export default class WebServiceClient {
9898
};
9999

100100
let data;
101+
/*
102+
We handle two kinds of errors here:
103+
1. Network errors, such as timeouts or CORS errors. These will be caught
104+
by the catch block and rethrown as a WebServiceClientError.
105+
2. Errors returned by the MaxMind web service, namely non-200 status codes. These
106+
will be caught by the handleBadServerResponse method and rethrown/rejected as a
107+
WebServiceClientError.
108+
*/
101109
try {
102110
const response = await fetch(url, options);
103111

104112
if (!response.ok) {
105-
return Promise.reject(await this.handleError(response, url));
113+
return Promise.reject(
114+
await this.handleBadServerResponse(response, url)
115+
);
106116
}
107117

108118
if (response.status === 204) {
@@ -136,7 +146,7 @@ export default class WebServiceClient {
136146
return new modelClass(data);
137147
}
138148

139-
private async handleError(
149+
private async handleBadServerResponse(
140150
response: Response,
141151
url: string
142152
): Promise<WebServiceClientError> {

0 commit comments

Comments
 (0)