Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix : #8825 If attachment token expires, it throws a 500 error instead of Unauthenticated #9043

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { ArgumentsHost, Catch, ExceptionFilter } from '@nestjs/common';

import { Response } from 'express';

import {
AuthException,
AuthExceptionCode,
} from 'src/engine/core-modules/auth/auth.exception';
import { HttpExceptionHandlerService } from 'src/engine/core-modules/exception-handler/http-exception-handler.service';

@Catch(AuthException)
export class AuthFileApiExceptionFilter implements ExceptionFilter {
constructor(
private readonly httpExceptionHandlerService: HttpExceptionHandlerService,
) {}

catch(exception: AuthException, host: ArgumentsHost) {
const ctx = host.switchToHttp();
const response = ctx.getResponse<Response>();

switch (exception.code) {
case AuthExceptionCode.UNAUTHENTICATED:
case AuthExceptionCode.INVALID_INPUT:
return this.httpExceptionHandlerService.handleError(
exception,
response,
403,
);
case AuthExceptionCode.INTERNAL_SERVER_ERROR:
default:
return this.httpExceptionHandlerService.handleError(
exception,
response,
500,
);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { Controller, Get, Param, Req, Res, UseGuards } from '@nestjs/common';
import {
Controller,
Get,
Param,
Req,
Res,
UseFilters,
UseGuards,
} from '@nestjs/common';

import { Response } from 'express';

Expand All @@ -7,6 +15,7 @@ import {
FileStorageExceptionCode,
} from 'src/engine/core-modules/file-storage/interfaces/file-storage-exception';

import { AuthFileApiExceptionFilter } from 'src/engine/core-modules/auth/filters/auth-file-api-exception.filter';
import {
checkFilePath,
checkFilename,
Expand All @@ -16,6 +25,7 @@ import { FileService } from 'src/engine/core-modules/file/services/file.service'

// TODO: Add cookie authentication
@Controller('files')
@UseFilters(AuthFileApiExceptionFilter)
@UseGuards(FilePathGuard)
export class FileController {
constructor(private readonly fileService: FileService) {}
Expand All @@ -27,7 +37,6 @@ export class FileController {
@Req() req: Request,
) {
const folderPath = checkFilePath(params[0]);

const filename = checkFilename(params['filename']);

const workspaceId = (req as any)?.workspaceId;
Expand Down
Loading