@lokalise/node-core
Advanced tools
Comparing version 8.4.1 to 9.0.0
@@ -23,3 +23,3 @@ /// <reference types="node" /> | ||
blobResponseBody?: boolean; | ||
requestLabel?: string; | ||
requestLabel: string; | ||
disableKeepAlive?: boolean; | ||
@@ -26,0 +26,0 @@ retryConfig?: RetryConfig; |
@@ -145,3 +145,3 @@ "use strict"; | ||
blobBody: options.blobResponseBody ?? false, | ||
throwOnInternalError: true, | ||
throwOnInternalError: false, | ||
requestLabel: options.requestLabel, | ||
@@ -164,3 +164,6 @@ }; | ||
if (requestResult.error && throwOnError) { | ||
throw new ResponseStatusError_1.ResponseStatusError(requestResult.error, requestLabel); | ||
if ((0, undici_retry_1.isRequestResult)(requestResult.error)) { | ||
throw new ResponseStatusError_1.ResponseStatusError(requestResult.error, requestLabel); | ||
} | ||
throw requestResult.error; | ||
} | ||
@@ -167,0 +170,0 @@ if (requestResult.result && validateResponse && validationSchema) { |
@@ -105,3 +105,3 @@ "use strict"; | ||
}); | ||
it('returns original payload when breaking during parsing', async () => { | ||
it('returns original payload when breaking during parsing and throw on error is true', async () => { | ||
expect.assertions(1); | ||
@@ -115,3 +115,7 @@ client | ||
try { | ||
await (0, httpClient_1.sendGet)(client, '/products/1', { safeParseJson: true, requestLabel: 'label' }); | ||
await (0, httpClient_1.sendGet)(client, '/products/1', { | ||
throwOnError: true, | ||
safeParseJson: true, | ||
requestLabel: 'label', | ||
}); | ||
} | ||
@@ -131,2 +135,24 @@ catch (err) { | ||
}); | ||
it('does not throw if broken during parsing but throwOnError is false', async () => { | ||
expect.assertions(1); | ||
client | ||
.intercept({ | ||
path: '/products/1', | ||
method: 'GET', | ||
}) | ||
.reply(200, 'this is not a real json', { headers: JSON_HEADERS }); | ||
const result = await (0, httpClient_1.sendGet)(client, '/products/1', { | ||
throwOnError: false, | ||
safeParseJson: true, | ||
requestLabel: 'label', | ||
}); | ||
expect(result.error).toMatchObject({ | ||
message: 'Error while parsing HTTP JSON response', | ||
errorCode: 'INVALID_HTTP_RESPONSE_JSON', | ||
details: { | ||
rawBody: 'this is not a real json', | ||
requestLabel: 'label', | ||
}, | ||
}); | ||
}); | ||
it('GET without queryParams', async () => { | ||
@@ -206,2 +232,3 @@ client | ||
requestLabel: 'label', | ||
throwOnError: true, | ||
query, | ||
@@ -215,3 +242,3 @@ }); | ||
expect(err.message).toBe('connect ECONNREFUSED 127.0.0.1:999'); | ||
expect(err.details.requestLabel).toBe('label'); | ||
expect(err.requestLabel).toBe('label'); | ||
} | ||
@@ -218,0 +245,0 @@ }); |
{ | ||
"name": "@lokalise/node-core", | ||
"version": "8.4.1", | ||
"version": "9.0.0", | ||
"author": { | ||
@@ -38,5 +38,5 @@ "name": "Lokalise", | ||
"dependencies": { | ||
"pino": "^8.17.0", | ||
"pino": "^8.17.1", | ||
"undici": "^6.0.1", | ||
"undici-retry": "^4.0.0" | ||
"undici-retry": "^5.0.2" | ||
}, | ||
@@ -43,0 +43,0 @@ "devDependencies": { |
@@ -46,3 +46,3 @@ # node-core 🧬 | ||
- `blobResponseBody`, used when the response body should be returned as Blob; | ||
- `requestLabel`, if set, will be returned together with any thrown or returned Error to provide additional context about what request was being executed when the error has happened; | ||
- `requestLabel`, this string will be returned together with any thrown or returned Error to provide additional context about what request was being executed when the error has happened; | ||
- `disableKeepAlive`;` | ||
@@ -49,0 +49,0 @@ - `retryConfig`, defined by: |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
261161
3342
+ Addedundici-retry@5.0.3(transitive)
- Removedundici-retry@4.0.0(transitive)
Updatedpino@^8.17.1
Updatedundici-retry@^5.0.2