-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix : #8825 If attachment token expires, it throws a 500 error instea…
…d of Unauthenticated (#9043) Fixes #8825 FilePathGuard implements token verification via verifyWorkspaceToken function which throws AuthException error , since CanActivate expects a boolean value , we add a try catch while verifying the token if token is invalid/expired <img width="1470" alt="Screenshot 2024-12-12 at 9 44 58 PM" src="https://github.com/user-attachments/assets/106a85dd-f894-46ea-80c3-f29b4ea5b4d3" /> else <img width="917" alt="Screenshot 2024-12-12 at 9 47 10 PM" src="https://github.com/user-attachments/assets/d82168f4-d140-48dc-94a4-56773a93db83" /> --------- Co-authored-by: Félix Malfait <[email protected]> Co-authored-by: Félix Malfait <[email protected]> Co-authored-by: Charles Bochet <[email protected]>
- Loading branch information
1 parent
d61409a
commit d324cac
Showing
7 changed files
with
108 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
packages/twenty-server/src/engine/core-modules/file/file.exception.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { CustomException } from 'src/utils/custom-exception'; | ||
|
||
export enum FileExceptionCode { | ||
UNAUTHENTICATED = 'UNAUTHENTICATED', | ||
INTERNAL_SERVER_ERROR = 'INTERNAL_SERVER_ERROR', | ||
FILE_NOT_FOUND = 'FILE_NOT_FOUND', | ||
} | ||
|
||
export class FileException extends CustomException { | ||
code: FileExceptionCode; | ||
constructor(message: string, code: FileExceptionCode) { | ||
super(message, code); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
packages/twenty-server/src/engine/core-modules/file/filters/file-api-exception.filter.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { ArgumentsHost, Catch, ExceptionFilter } from '@nestjs/common'; | ||
|
||
import { Response } from 'express'; | ||
|
||
import { HttpExceptionHandlerService } from 'src/engine/core-modules/exception-handler/http-exception-handler.service'; | ||
import { | ||
FileException, | ||
FileExceptionCode, | ||
} from 'src/engine/core-modules/file/file.exception'; | ||
|
||
@Catch(FileException) | ||
export class FileApiExceptionFilter implements ExceptionFilter { | ||
constructor( | ||
private readonly httpExceptionHandlerService: HttpExceptionHandlerService, | ||
) {} | ||
|
||
catch(exception: FileException, host: ArgumentsHost) { | ||
const ctx = host.switchToHttp(); | ||
const response = ctx.getResponse<Response>(); | ||
|
||
switch (exception.code) { | ||
case FileExceptionCode.UNAUTHENTICATED: | ||
return this.httpExceptionHandlerService.handleError( | ||
exception, | ||
response, | ||
403, | ||
); | ||
case FileExceptionCode.FILE_NOT_FOUND: | ||
return this.httpExceptionHandlerService.handleError( | ||
exception, | ||
response, | ||
404, | ||
); | ||
case FileExceptionCode.INTERNAL_SERVER_ERROR: | ||
default: | ||
return this.httpExceptionHandlerService.handleError( | ||
exception, | ||
response, | ||
500, | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters