Skip to content

Commit 1d5bd36

Browse files
committed
Fix:If attachment token expires, it throws a 500 error instead of Unauthenticated
This fixes this issue by throwing a descriptive error instead of a server error 500
1 parent ab8ad46 commit 1d5bd36

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

packages/twenty-server/src/engine/core-modules/graphql/utils/graphql-errors.util.ts

+6
Original file line numberDiff line numberDiff line change
@@ -191,3 +191,9 @@ export class InternalServerError extends BaseGraphQLError {
191191
Object.defineProperty(this, 'name', { value: 'InternalServerError' });
192192
}
193193
}
194+
195+
export class ExpiredAttachmentTokenError extends BaseGraphQLError {
196+
constructor(message = 'The attachment token has expired') {
197+
super(message, ErrorCode.UNAUTHENTICATED);
198+
}
199+
}

packages/twenty-server/src/engine/utils/global-exception-handler.util.ts

+9-4
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ import {
1111
BaseGraphQLError,
1212
ConflictError,
1313
ErrorCode,
14+
ExpiredAttachmentTokenError,
1415
ForbiddenError,
1516
MethodNotAllowedError,
1617
NotFoundError,
1718
TimeoutError,
18-
ValidationError,
19+
ValidationError
1920
} from 'src/engine/core-modules/graphql/utils/graphql-errors.util';
2021

2122
const graphQLPredefinedExceptions = {
@@ -101,12 +102,16 @@ export const convertExceptionToGraphQLError = (
101102
const convertHttpExceptionToGraphql = (exception: HttpException) => {
102103
const status = exception.getStatus();
103104
let error: BaseGraphQLError;
105+
const message = exception.getResponse()['message'] ?? exception.message;
104106

105107
if (status in graphQLPredefinedExceptions) {
106-
const message = exception.getResponse()['message'] ?? exception.message;
107-
108108
error = new graphQLPredefinedExceptions[exception.getStatus()](message);
109-
} else {
109+
110+
} else if (message.includes('attachment token expired')) {
111+
// Check if the error message indicates an expired attachment token
112+
error = new ExpiredAttachmentTokenError(message);
113+
}
114+
else {
110115
error = new BaseGraphQLError(
111116
'Internal Server Error',
112117
exception.getStatus().toString(),

0 commit comments

Comments
 (0)