Skip to content
This repository was archived by the owner on Jul 13, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 0 additions & 17 deletions src/http-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,23 +104,6 @@ export class HttpClient {
)
}

// We don't have a body, so it's an unpredictable error, but let's try to structure it
// anyways for completeness sake
if (badRequest && !data) {
throw apiErrorFactory(
{
code: status.toString(),
details: res.statusText,
},
headers,
)
}

// should not happen, but a catch all just in case
if (badRequest) {
throw new InvalidProgramStateError(data)
}

if (status < this.httpStatus.MULTIPLE_CHOICES && data) {
return data
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
{
"log": {
"_recordingName": "HttpClient/get/should throw an exception base on http status when request return object without code ",
"creator": {
"comment": "persister:fs",
"name": "Polly.JS",
"version": "5.1.0"
},
"entries": [
{
"_id": "2da808cdd3d89cb18c7128a19ffd1e4d",
"_order": 0,
"cache": {},
"request": {
"bodySize": 0,
"cookies": [],
"headers": [
{
"name": "accept",
"value": "application/json"
},
{
"name": "content-type",
"value": "application/json"
},
{
"name": "user-agent",
"value": "@scaleleap/amazon-advertising-api-sdk/0.0.0"
},
{
"name": "amazon-advertising-api-scope",
"value": "-1"
},
{
"name": "bidding_controls_on",
"value": "true"
},
{
"name": "accept-encoding",
"value": "application/json"
},
{
"name": "host",
"value": "advertising-api-test.amazon.com"
}
],
"headersSize": 372,
"httpVersion": "HTTP/1.1",
"method": "GET",
"queryString": [],
"url": "https://advertising-api-test.amazon.com/foobar"
},
"response": {
"bodySize": 153,
"content": {
"mimeType": "application/json; charset=utf-8",
"size": 153,
"text": {
"details": "Request was rate-limited. Retry later."
}
},
"cookies": [],
"headers": [
{
"name": "server",
"value": "Server"
},
{
"name": "date",
"value": "Thu, 14 Jan 2021 15:33:08 GMT"
},
{
"name": "content-type",
"value": "application/json; charset=utf-8"
},
{
"name": "content-length",
"value": "153"
},
{
"name": "connection",
"value": "close"
},
{
"name": "x-amz-request-id",
"value": "3323JGVBWRRQMXR22A31"
},
{
"name": "vary",
"value": "Content-Type,Accept-Encoding,X-Amzn-CDN-Cache,X-Amzn-AX-Treatment,User-Agent"
}
],
"headersSize": 299,
"httpVersion": "HTTP/1.1",
"redirectURL": "",
"status": 429,
"statusText": "OK"
},
"startedDateTime": "2021-01-14T15:33:07.160Z",
"time": 1554,
"timings": {
"blocked": -1,
"connect": -1,
"dns": -1,
"receive": 0,
"send": 0,
"ssl": -1,
"wait": 1554
}
}
],
"pages": [],
"version": "1.2"
}
}
16 changes: 16 additions & 0 deletions test/http-client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,22 @@ describe('HttpClient', () => {
expect(err.retryAfter).toBe(42)
})
})

it('should throw an exception base on http status when request return object without code ', async () => {
const server = jestPollyContext.polly.server
const details = 'Request was rate-limited. Retry later.'

server.get(SANDBOX_URI + '/foobar').on('beforeResponse', (req, res) => {
res.status(HttpStatus.TOO_MANY_REQUESTS)
res.send({
details,
})
})

await client.get('foobar').catch((err: ThrottlingError) => {
expect(err.message).toContain(details)
})
})
})

describe('download', () => {
Expand Down