The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
fix(server): honor the statusCode option CustomException declares (#24534)
Félix Malfait972bac2139ce
diff --git a/packages/twenty-server/src/utils/__test__/custom-exception.spec.ts b/packages/twenty-server/src/utils/__test__/custom-exception.spec.tsindex 39e7da7d9ea..54d6a7ae472 100644--- a/packages/twenty-server/src/utils/__test__/custom-exception.spec.ts+++ b/packages/twenty-server/src/utils/__test__/custom-exception.spec.ts@@ -31,6 +31,23 @@ describe('appendCommonExceptionCode', () => {});describe('CustomException', () => {+ it('should assign the statusCode option when provided', () => {+ const exception = new UnknownException('Not found', 'NOT_FOUND', {+ userFriendlyMessage: msg`Not found`,+ statusCode: 404,+ });++ expect(exception.statusCode).toBe(404);+ });++ it('should leave statusCode undefined when the option is omitted', () => {+ const exception = new UnknownException('Boom', 'INTERNAL_SERVER_ERROR', {+ userFriendlyMessage: msg`Boom`,+ });++ expect(exception.statusCode).toBeUndefined();+ });+class TestException extends CustomException<string> {constructor(message: string,diff --git a/packages/twenty-server/src/utils/custom-exception.ts b/packages/twenty-server/src/utils/custom-exception.tsindex db473a57e17..98bb0e3ade8 100644--- a/packages/twenty-server/src/utils/custom-exception.ts+++ b/packages/twenty-server/src/utils/custom-exception.ts@@ -29,11 +29,13 @@ export abstract class CustomException<code: ExceptionCode,{userFriendlyMessage,+ statusCode,}: { userFriendlyMessage: MessageDescriptor; statusCode?: number },) {super(message);this.code = code;this.userFriendlyMessage = userFriendlyMessage;+ this.statusCode = statusCode;}}