diff --git a/webapp/platform/client/src/client4.test.ts b/webapp/platform/client/src/client4.test.ts index a684b5199a..d6a4eed31d 100644 --- a/webapp/platform/client/src/client4.test.ts +++ b/webapp/platform/client/src/client4.test.ts @@ -68,6 +68,24 @@ describe('ClientError', () => { expect(copy.status_code).toEqual(error.status_code); expect(copy.url).toEqual(error.url); }); + + test('cause should be preserved when provided', () => { + const cause = new Error('the original error'); + const error = new ClientError('https://example.com', { + message: 'This is a message', + server_error_id: 'test.app_error', + status_code: 418, + url: 'https://example.com/api/v4/error', + }, cause); + + const copy = {...error}; + + expect(copy.message).toEqual(error.message); + expect(copy.server_error_id).toEqual(error.server_error_id); + expect(copy.status_code).toEqual(error.status_code); + expect(copy.url).toEqual(error.url); + expect(error.cause).toEqual(cause); + }); }); describe('trackEvent', () => { diff --git a/webapp/platform/client/src/client4.ts b/webapp/platform/client/src/client4.ts index 47e6741b0e..ba9d713775 100644 --- a/webapp/platform/client/src/client4.ts +++ b/webapp/platform/client/src/client4.ts @@ -4168,7 +4168,7 @@ export default class Client4 { throw new ClientError(this.getUrl(), { message: 'Received invalid response from the server.', url, - }); + }, err); } if (headers.has(HEADER_X_VERSION_ID) && !headers.get('Cache-Control')) { @@ -4311,8 +4311,8 @@ export class ClientError extends Error implements ServerError { server_error_id?: string; status_code?: number; - constructor(baseUrl: string, data: ServerError) { - super(data.message + ': ' + cleanUrlForLogging(baseUrl, data.url || '')); + constructor(baseUrl: string, data: ServerError, cause?: any) { + super(data.message + ': ' + cleanUrlForLogging(baseUrl, data.url || ''), {cause}); this.message = data.message; this.url = data.url; diff --git a/webapp/platform/client/tsconfig.json b/webapp/platform/client/tsconfig.json index 992f9814f1..2dad4b02eb 100644 --- a/webapp/platform/client/tsconfig.json +++ b/webapp/platform/client/tsconfig.json @@ -2,7 +2,7 @@ "compilerOptions": { "module": "commonjs", "moduleResolution": "node", - "target": "es6", + "target": "es2022", "declaration": true, "strict": true, "resolveJsonModule": true,