balena-request
Advanced tools
Comparing version 13.1.0 to 13.2.0-build-expose-retry-after-9bce8edb035392b57dcb075ad832bb4ffa865f72-1
@@ -191,3 +191,3 @@ "use strict"; | ||
debugRequest(options, response); | ||
throw new errors.BalenaRequestError(responseError, response.statusCode, options); | ||
throw new errors.BalenaRequestError(responseError, response.statusCode, options, response.headers); | ||
} | ||
@@ -194,0 +194,0 @@ return response; |
@@ -7,2 +7,7 @@ # Change Log | ||
## 13.2.0 - 2023-11-01 | ||
* Include the response headers in BalenaRequestErrors [Thodoris Greasidis] | ||
* Stop using require-npm4-to-publish [Thodoris Greasidis] | ||
## 13.1.0 - 2023-10-30 | ||
@@ -9,0 +14,0 @@ |
@@ -299,2 +299,3 @@ /* | ||
options, | ||
response.headers, | ||
); | ||
@@ -301,0 +302,0 @@ } |
{ | ||
"name": "balena-request", | ||
"version": "13.1.0", | ||
"version": "13.2.0-build-expose-retry-after-9bce8edb035392b57dcb075ad832bb4ffa865f72-1", | ||
"description": "Balena HTTP client", | ||
@@ -32,3 +32,2 @@ "main": "build/request.js", | ||
"build": "npx tsc", | ||
"prepublish": "require-npm4-to-publish", | ||
"prepare": "npm run build", | ||
@@ -62,3 +61,2 @@ "readme": "jsdoc2md --template doc/README.hbs build/request.js build/progress.js build/utils.js > README.md" | ||
"querystring-es3": "^0.2.1", | ||
"require-npm4-to-publish": "^1.0.0", | ||
"rindle": "^1.3.6", | ||
@@ -75,3 +73,3 @@ "sinon": "^15.0.1", | ||
"@balena/node-web-streams": "^0.2.3", | ||
"balena-errors": "^4.7.3", | ||
"balena-errors": "^4.9.0", | ||
"fetch-ponyfill": "^7.1.0", | ||
@@ -90,4 +88,4 @@ "fetch-readablestream": "^0.2.0", | ||
"versionist": { | ||
"publishedAt": "2023-10-30T16:16:38.587Z" | ||
"publishedAt": "2023-11-01T13:42:29.151Z" | ||
} | ||
} |
@@ -0,1 +1,2 @@ | ||
import * as errors from 'balena-errors'; | ||
import { expect } from 'chai'; | ||
@@ -167,2 +168,161 @@ import setup from './setup'; | ||
}); | ||
describe('given a ratelimiting response error without a Retry-After header', function () { | ||
beforeEach(() => | ||
mockServer.forGet('/429').thenReply(429, '"Too Many Requests"', { | ||
'Content-Length': '19', | ||
'Content-Type': 'application/json', | ||
Date: 'Tue, 31 Oct 2023 14:28:22 GMT', | ||
}), | ||
); | ||
it('should not include Retry-After in the headers', async function () { | ||
await expect( | ||
request.send({ | ||
method: 'GET', | ||
baseUrl: mockServer.url, | ||
url: '/429', | ||
}), | ||
).to.be.rejected.then((error) => { | ||
expect(error).to.be.an.instanceOf(errors.BalenaRequestError); | ||
expect(error).to.have.property('statusCode', 429); | ||
expect(error).to.have.property('name', 'BalenaRequestError'); | ||
expect(error).to.have.property('body', 'Too Many Requests'); | ||
expect(error).to.have.property('responseHeaders'); | ||
expect(error.responseHeaders.get('Retry-After')).to.equal(null); | ||
}); | ||
}); | ||
}); | ||
describe('given a ratelimiting response error with a Retry-After header', function () { | ||
const responseHeadersWithRetryAfter = { | ||
'Retry-After': '60', | ||
'Content-Length': '19', | ||
'Content-Type': 'application/json', | ||
Date: 'Tue, 31 Oct 2023 14:28:22 GMT', | ||
}; | ||
describe('when the http server does not specify the Retry-After in the Access-Control-Expose-Headers', function () { | ||
beforeEach(async () => { | ||
await mockServer | ||
.forGet('/429') | ||
.thenReply( | ||
429, | ||
'"Too Many Requests"', | ||
responseHeadersWithRetryAfter, | ||
); | ||
}); | ||
if (IS_BROWSER) { | ||
it('should not include Retry-After in the headers', async function () { | ||
await expect( | ||
request.send({ | ||
method: 'GET', | ||
baseUrl: mockServer.url, | ||
url: '/429', | ||
}), | ||
).to.be.rejected.then((error) => { | ||
expect(error).to.be.an.instanceOf(errors.BalenaRequestError); | ||
expect(error).to.have.property('statusCode', 429); | ||
expect(error).to.have.property('name', 'BalenaRequestError'); | ||
expect(error).to.have.property('body', 'Too Many Requests'); | ||
expect(error).to.have.property('responseHeaders'); | ||
expect(error.responseHeaders.get('Retry-After')).to.equal( | ||
null, | ||
); | ||
}); | ||
}); | ||
} else { | ||
it('should include Retry-After in the headers', async function () { | ||
await expect( | ||
request.send({ | ||
method: 'GET', | ||
baseUrl: mockServer.url, | ||
url: '/429', | ||
}), | ||
).to.be.rejected.then((error) => { | ||
expect(error).to.be.an.instanceOf(errors.BalenaRequestError); | ||
expect(error).to.have.property('statusCode', 429); | ||
expect(error).to.have.property('name', 'BalenaRequestError'); | ||
expect(error).to.have.property('body', 'Too Many Requests'); | ||
expect(error).to.have.property('responseHeaders'); | ||
expect(error.responseHeaders.get('Retry-After')).to.equal( | ||
'60', | ||
); | ||
}); | ||
}); | ||
} | ||
}); | ||
describe('when the http server specifies the Access-Control-Expose-Headers=Retry-After in the GET response headers', function () { | ||
beforeEach(async () => { | ||
await mockServer | ||
.forGet('/429') | ||
.thenReply(429, '"Too Many Requests"', { | ||
...responseHeadersWithRetryAfter, | ||
'Access-Control-Expose-Headers': 'Retry-After', | ||
}); | ||
}); | ||
it('should include Retry-After in the headers', async function () { | ||
await expect( | ||
request.send({ | ||
method: 'GET', | ||
baseUrl: mockServer.url, | ||
url: '/429', | ||
}), | ||
).to.be.rejected.then((error) => { | ||
expect(error).to.be.an.instanceOf(errors.BalenaRequestError); | ||
expect(error).to.have.property('statusCode', 429); | ||
expect(error).to.have.property('name', 'BalenaRequestError'); | ||
expect(error).to.have.property('body', 'Too Many Requests'); | ||
expect(error).to.have.property('responseHeaders'); | ||
expect(error.responseHeaders.get('Retry-After')).to.equal('60'); | ||
}); | ||
}); | ||
}); | ||
describe('when the http server specifies the Access-Control-Expose-Headers=Retry-After in the OPTIONS response headers', function () { | ||
let mockServer2; | ||
beforeEach(async () => { | ||
await mockServer.stop(); | ||
mockServer2 = mockhttp.getLocal({ | ||
cors: { | ||
exposedHeaders: 'Retry-After', | ||
}, | ||
}); | ||
await mockServer2.start(); | ||
await mockServer2 | ||
.forGet('/429') | ||
.thenReply( | ||
429, | ||
'"Too Many Requests"', | ||
responseHeadersWithRetryAfter, | ||
); | ||
}); | ||
afterEach(async function () { | ||
await mockServer2.stop(); | ||
await mockServer.start(); | ||
}); | ||
it('should include Retry-After in the headers', async function () { | ||
await expect( | ||
request.send({ | ||
method: 'GET', | ||
baseUrl: mockServer2.url, | ||
url: '/429', | ||
}), | ||
).to.be.rejected.then((error) => { | ||
expect(error).to.be.an.instanceOf(errors.BalenaRequestError); | ||
expect(error).to.have.property('statusCode', 429); | ||
expect(error).to.have.property('name', 'BalenaRequestError'); | ||
expect(error).to.have.property('body', 'Too Many Requests'); | ||
expect(error).to.have.property('responseHeaders'); | ||
expect(error.responseHeaders.get('Retry-After')).to.equal('60'); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
@@ -169,0 +329,0 @@ |
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
226575
30
4400
1
Updatedbalena-errors@^4.9.0