Skip to content

Commit 0e09eb5

Browse files
authored
Merge pull request #1491 from maxmind/kevin/fetch
Use built-in fetch
2 parents cd4627b + 3d1c974 commit 0e09eb5

File tree

6 files changed

+186
-86
lines changed

6 files changed

+186
-86
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
CHANGELOG
22
=========
33

4-
7.1.0
4+
8.0.0
55
-----------------
66

7+
* **Breaking** Internal webservice calls now use Node's built-in `fetch` instead of `http`. This
8+
will affect users who are on unsupported versions of Node, specifically Node 17 and below.
9+
* Two new error codes have been added: `NETWORK_TIMEOUT` and `FETCH_ERROR`, second of which is returned
10+
when there's a `fetch` related error that could not be handled by other errors.
711
* The minFraud Factors subscores have been deprecated. They will be removed
812
in March 2025. Please see [our release notes](https://dev.maxmind.com/minfraud/release-notes/2024/#deprecation-of-risk-factor-scoressubscores)
913
for more information.

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,16 @@ returned by the web API, we also return:
151151
code: 'INVALID_RESPONSE_BODY',
152152
error: <string>
153153
}
154+
155+
{
156+
code: 'NETWORK_TIMEOUT',
157+
error: <string>
158+
}
159+
160+
{
161+
code: 'FETCH_ERROR',
162+
error: <string>
163+
}
154164
```
155165

156166
## Example

package-lock.json

Lines changed: 64 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"gh-pages": "^6.0.0",
3333
"globals": "^15.9.0",
3434
"jest": "^29.5.0",
35-
"nock": "^13.0.2",
35+
"nock": "^14.0.0-beta.16",
3636
"prettier": "^3.0.0",
3737
"ts-jest": "^29.1.0",
3838
"typedoc": "^0.26.3",

src/webServiceClient.spec.ts

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -879,12 +879,33 @@ describe('WebServiceClient', () => {
879879
});
880880

881881
describe('error handling', () => {
882+
afterEach(() => {
883+
nock.cleanAll();
884+
});
885+
882886
const transaction = new Transaction({
883887
device: new Device({
884888
ipAddress: '1.1.1.1',
885889
}),
886890
});
887891

892+
it('handles timeouts', () => {
893+
const timeoutClient = new Client(auth.user, auth.pass, 10);
894+
expect.assertions(1);
895+
896+
nockInstance
897+
.post(fullPath('score'), score.request.basic)
898+
.basicAuth(auth)
899+
.delayConnection(100)
900+
.reply(200, score.response.full);
901+
902+
return expect(timeoutClient.score(transaction)).rejects.toEqual({
903+
code: 'NETWORK_TIMEOUT',
904+
error: 'The request timed out',
905+
url: baseUrl + fullPath('score'),
906+
});
907+
});
908+
888909
it('handles 5xx level errors', () => {
889910
expect.assertions(1);
890911

@@ -930,15 +951,12 @@ describe('WebServiceClient', () => {
930951
});
931952
});
932953

933-
it('handles general http.request errors', () => {
934-
const error = {
935-
code: 'FOO_ERR',
936-
message: 'some foo error',
937-
};
954+
it('handles general fetch errors', () => {
955+
const error = 'general error';
938956

939957
const expected = {
940-
code: error.code,
941-
error: error.message,
958+
code: 'FETCH_ERROR',
959+
error: `Error - ${error}`,
942960
url: baseUrl + fullPath('score'),
943961
};
944962

0 commit comments

Comments
 (0)