From 8513e9b7f3513287c60646b49371f77ffd84fdaf Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Mon, 7 Feb 2022 01:02:47 +0000 Subject: [PATCH 1/2] fix(deps): update dependency node-fetch to v3 --- package-lock.json | 167 +++++++++++++++++++++++++++++++--------------- package.json | 2 +- 2 files changed, 115 insertions(+), 54 deletions(-) diff --git a/package-lock.json b/package-lock.json index 4328e50..079bf7e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,7 +12,7 @@ "@netlify/open-api": "^2.8.0", "lodash.camelcase": "^4.3.0", "micro-api-client": "^3.3.0", - "node-fetch": "^2.6.1", + "node-fetch": "^3.0.0", "omit.js": "^2.0.2", "p-wait-for": "^3.2.0", "qs": "^6.9.6" @@ -2569,6 +2569,14 @@ "node": ">=8" } }, + "node_modules/data-uri-to-buffer": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-4.0.0.tgz", + "integrity": "sha512-Vr3mLBA8qWmcuschSLAOogKgQ/Jwxulv3RNE4FXnYWRGujzrRWQI4m12fQqRkwX06C0KanhLr4hK+GydchZsaA==", + "engines": { + "node": ">= 12" + } + }, "node_modules/date-time": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/date-time/-/date-time-3.1.0.tgz", @@ -3971,6 +3979,28 @@ "reusify": "^1.0.4" } }, + "node_modules/fetch-blob": { + "version": "3.1.4", + "resolved": "https://registry.npmjs.org/fetch-blob/-/fetch-blob-3.1.4.tgz", + "integrity": "sha512-Eq5Xv5+VlSrYWEqKrusxY1C3Hm/hjeAsCGVG3ft7pZahlUAChpGZT/Ms1WmSLnEAisEXszjzu/s+ce6HZB2VHA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/jimmywarting" + }, + { + "type": "paypal", + "url": "https://paypal.me/jimmywarting" + } + ], + "dependencies": { + "node-domexception": "^1.0.0", + "web-streams-polyfill": "^3.0.3" + }, + "engines": { + "node": "^12.20 || >= 14.13" + } + }, "node_modules/figures": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/figures/-/figures-3.2.0.tgz", @@ -4058,6 +4088,17 @@ "node": ">=8.0.0" } }, + "node_modules/formdata-polyfill": { + "version": "4.0.10", + "resolved": "https://registry.npmjs.org/formdata-polyfill/-/formdata-polyfill-4.0.10.tgz", + "integrity": "sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==", + "dependencies": { + "fetch-blob": "^3.1.2" + }, + "engines": { + "node": ">=12.20.0" + } + }, "node_modules/from2": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/from2/-/from2-2.3.0.tgz", @@ -5928,23 +5969,39 @@ "node": ">= 10.13" } }, + "node_modules/node-domexception": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz", + "integrity": "sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/jimmywarting" + }, + { + "type": "github", + "url": "https://paypal.me/jimmywarting" + } + ], + "engines": { + "node": ">=10.5.0" + } + }, "node_modules/node-fetch": { - "version": "2.6.7", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz", - "integrity": "sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==", + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-3.2.0.tgz", + "integrity": "sha512-8xeimMwMItMw8hRrOl3C9/xzU49HV/yE6ORew/l+dxWimO5A4Ra8ld2rerlJvc/O7et5Z1zrWsPX43v1QBjCxw==", "dependencies": { - "whatwg-url": "^5.0.0" + "data-uri-to-buffer": "^4.0.0", + "fetch-blob": "^3.1.4", + "formdata-polyfill": "^4.0.10" }, "engines": { - "node": "4.x || >=6.0.0" + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" }, - "peerDependencies": { - "encoding": "^0.1.0" - }, - "peerDependenciesMeta": { - "encoding": { - "optional": true - } + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/node-fetch" } }, "node_modules/node-releases": { @@ -8041,11 +8098,6 @@ "node": ">=8.0" } }, - "node_modules/tr46": { - "version": "0.0.3", - "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", - "integrity": "sha1-gYT9NH2snNwYWZLzpmIuFLnZq2o=" - }, "node_modules/trim-newlines": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/trim-newlines/-/trim-newlines-3.0.1.tgz", @@ -8436,10 +8488,13 @@ "defaults": "^1.0.3" } }, - "node_modules/webidl-conversions": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", - "integrity": "sha1-JFNCdeKnvGvnvIZhHMFq4KVlSHE=" + "node_modules/web-streams-polyfill": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-3.2.0.tgz", + "integrity": "sha512-EqPmREeOzttaLRm5HS7io98goBgZ7IVz79aDvqjD0kYXLtFZTc0T/U6wHTPKyIjb+MdN7DFIIX6hgdBEpWmfPA==", + "engines": { + "node": ">= 8" + } }, "node_modules/well-known-symbols": { "version": "2.0.0", @@ -8450,15 +8505,6 @@ "node": ">=6" } }, - "node_modules/whatwg-url": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz", - "integrity": "sha1-lmRU6HZUYuN2RNNib2dCzotwll0=", - "dependencies": { - "tr46": "~0.0.3", - "webidl-conversions": "^3.0.0" - } - }, "node_modules/which": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", @@ -10521,6 +10567,11 @@ "integrity": "sha512-2iy1EkLdlBzQGvbweYRFxmFath8+K7+AKB0TlhHWkNuH+TmovaMH/Wp7V7R4u7f4SnX3OgLsU9t1NI9ioDnUpg==", "dev": true }, + "data-uri-to-buffer": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-4.0.0.tgz", + "integrity": "sha512-Vr3mLBA8qWmcuschSLAOogKgQ/Jwxulv3RNE4FXnYWRGujzrRWQI4m12fQqRkwX06C0KanhLr4hK+GydchZsaA==" + }, "date-time": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/date-time/-/date-time-3.1.0.tgz", @@ -11557,6 +11608,15 @@ "reusify": "^1.0.4" } }, + "fetch-blob": { + "version": "3.1.4", + "resolved": "https://registry.npmjs.org/fetch-blob/-/fetch-blob-3.1.4.tgz", + "integrity": "sha512-Eq5Xv5+VlSrYWEqKrusxY1C3Hm/hjeAsCGVG3ft7pZahlUAChpGZT/Ms1WmSLnEAisEXszjzu/s+ce6HZB2VHA==", + "requires": { + "node-domexception": "^1.0.0", + "web-streams-polyfill": "^3.0.3" + } + }, "figures": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/figures/-/figures-3.2.0.tgz", @@ -11620,6 +11680,14 @@ "signal-exit": "^3.0.2" } }, + "formdata-polyfill": { + "version": "4.0.10", + "resolved": "https://registry.npmjs.org/formdata-polyfill/-/formdata-polyfill-4.0.10.tgz", + "integrity": "sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==", + "requires": { + "fetch-blob": "^3.1.2" + } + }, "from2": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/from2/-/from2-2.3.0.tgz", @@ -12975,12 +13043,19 @@ "propagate": "^2.0.0" } }, + "node-domexception": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz", + "integrity": "sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==" + }, "node-fetch": { - "version": "2.6.7", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz", - "integrity": "sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==", + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-3.2.0.tgz", + "integrity": "sha512-8xeimMwMItMw8hRrOl3C9/xzU49HV/yE6ORew/l+dxWimO5A4Ra8ld2rerlJvc/O7et5Z1zrWsPX43v1QBjCxw==", "requires": { - "whatwg-url": "^5.0.0" + "data-uri-to-buffer": "^4.0.0", + "fetch-blob": "^3.1.4", + "formdata-polyfill": "^4.0.10" } }, "node-releases": { @@ -14524,11 +14599,6 @@ "is-number": "^7.0.0" } }, - "tr46": { - "version": "0.0.3", - "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", - "integrity": "sha1-gYT9NH2snNwYWZLzpmIuFLnZq2o=" - }, "trim-newlines": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/trim-newlines/-/trim-newlines-3.0.1.tgz", @@ -14815,10 +14885,10 @@ "defaults": "^1.0.3" } }, - "webidl-conversions": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", - "integrity": "sha1-JFNCdeKnvGvnvIZhHMFq4KVlSHE=" + "web-streams-polyfill": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-3.2.0.tgz", + "integrity": "sha512-EqPmREeOzttaLRm5HS7io98goBgZ7IVz79aDvqjD0kYXLtFZTc0T/U6wHTPKyIjb+MdN7DFIIX6hgdBEpWmfPA==" }, "well-known-symbols": { "version": "2.0.0", @@ -14826,15 +14896,6 @@ "integrity": "sha512-ZMjC3ho+KXo0BfJb7JgtQ5IBuvnShdlACNkKkdsqBmYw3bPAaJfPeYUo6tLUaT5tG/Gkh7xkpBhKRQ9e7pyg9Q==", "dev": true }, - "whatwg-url": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz", - "integrity": "sha1-lmRU6HZUYuN2RNNib2dCzotwll0=", - "requires": { - "tr46": "~0.0.3", - "webidl-conversions": "^3.0.0" - } - }, "which": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", diff --git a/package.json b/package.json index fd6b879..1a82a3d 100644 --- a/package.json +++ b/package.json @@ -55,7 +55,7 @@ "@netlify/open-api": "^2.8.0", "lodash.camelcase": "^4.3.0", "micro-api-client": "^3.3.0", - "node-fetch": "^2.6.1", + "node-fetch": "^3.0.0", "omit.js": "^2.0.2", "p-wait-for": "^3.2.0", "qs": "^6.9.6" From 5372d8b125cd89f5fc2cd35729c5bd95ffdf8e23 Mon Sep 17 00:00:00 2001 From: ehmicky Date: Mon, 7 Feb 2022 19:00:15 +0100 Subject: [PATCH 2/2] chore!: fix new version of `node-fetch` --- src/index.test.js | 15 ++++++++------- src/methods/response.js | 13 ++++++++++--- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/index.test.js b/src/index.test.js index 68a2d91..6dc6b63 100644 --- a/src/index.test.js +++ b/src/index.test.js @@ -314,14 +314,15 @@ test('Can parse text responses', async (t) => { test('Handle error empty responses', async (t) => { const accountId = uuidv4() const status = 404 - const scope = nock(origin).get(`${pathPrefix}/accounts/${accountId}`).reply(status) + const expectedResponse = 'test' + const scope = nock(origin).get(`${pathPrefix}/accounts/${accountId}`).reply(status, expectedResponse) const client = getClient() const error = await t.throwsAsync(client.getAccount({ account_id: accountId })) t.is(error.status, status) - t.is(error.message, 'Not Found') - t.is(error.data, '') + t.is(error.message, expectedResponse) + t.is(error.data, expectedResponse) t.true(error instanceof TextHTTPError) t.true(error.stack !== undefined) t.true(scope.isDone()) @@ -337,7 +338,7 @@ test('Handle error text responses', async (t) => { const error = await t.throwsAsync(client.getAccount({ account_id: accountId })) t.is(error.status, status) - t.is(error.message, 'Not Found') + t.is(error.message, expectedResponse) t.is(error.data, expectedResponse) t.true(error instanceof TextHTTPError) t.true(error.stack !== undefined) @@ -356,7 +357,7 @@ test('Handle error text responses on JSON endpoints', async (t) => { const error = await t.throwsAsync(client.getAccount({ account_id: accountId })) t.is(error.status, status) - t.is(error.message, 'Not Found') + t.is(error.message, expectedResponse) t.is(error.data, expectedResponse) t.true(error instanceof TextHTTPError) t.true(error.stack !== undefined) @@ -373,7 +374,7 @@ test('Handle error JSON responses', async (t) => { const error = await t.throwsAsync(client.getAccount({ account_id: accountId })) t.is(error.status, status) - t.is(error.message, 'Not Found') + t.notThrows(() => JSON.parse(error.message)) t.deepEqual(error.json, errorJson) t.true(error instanceof JSONHTTPError) t.true(error.stack !== undefined) @@ -550,7 +551,7 @@ test('Gives up retrying on API rate limiting after a timeout', async (t) => { const error = await t.throwsAsync(client.getAccount({ account_id: accountId })) t.is(error.status, 429) - t.is(error.message, 'Too Many Requests') + t.is(error.message, JSON.stringify({ retryAt })) t.true(Number.isInteger(error.json.retryAt)) t.false(scope.isDone()) diff --git a/src/methods/response.js b/src/methods/response.js index ba8d74e..548a153 100644 --- a/src/methods/response.js +++ b/src/methods/response.js @@ -10,7 +10,7 @@ export const parseResponse = async function (response) { if (!response.ok) { const ErrorType = responseType === 'json' ? JSONHTTPError : TextHTTPError - throw new ErrorType(response, parsedResponse) + throw addFallbackErrorMessage(new ErrorType(response, parsedResponse), textResponse) } return parsedResponse @@ -34,13 +34,20 @@ const parseJsonResponse = function (response, textResponse, responseType) { try { return JSON.parse(textResponse) } catch { - throw new TextHTTPError(response, textResponse) + throw addFallbackErrorMessage(new TextHTTPError(response, textResponse), textResponse) } } +const addFallbackErrorMessage = function (error, textResponse) { + error.message = error.message || textResponse + return error +} + export const getFetchError = function (error, url, opts) { const data = omit.default(opts, ['Authorization']) - error.name = 'FetchError' + if (error.name !== 'FetchError') { + error.name = 'FetchError' + } error.url = url error.data = data return error