Browse Source

fix: handle exception error response in similar way

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/5444/head
Pranav C 2 years ago
parent
commit
b3775b5ed3
  1. 2
      packages/nocodb-nest/src/app.module.ts
  2. 29
      packages/nocodb-nest/src/filters/global-exception/global-exception.filter.ts
  3. 12
      packages/nocodb-nest/src/modules/attachments/attachments.controller.ts

2
packages/nocodb-nest/src/app.module.ts

@ -143,7 +143,7 @@ export const JwtStrategyProvider: Provider = {
},
// JwtStrategyProvider,
LocalStrategy,
ExtractProjectIdMiddleware,
// ExtractProjectIdMiddleware,
ClientService,
AuthTokenStrategy,
BaseViewStrategy,

29
packages/nocodb-nest/src/filters/global-exception/global-exception.filter.ts

@ -15,8 +15,6 @@ import type { Response } from 'express';
@Catch()
export class GlobalExceptionFilter implements ExceptionFilter {
catch(exception: any, host: ArgumentsHost) {
console.log(exception)
const ctx = host.switchToHttp();
const response = ctx.getResponse<Response>();
@ -28,17 +26,32 @@ export class GlobalExceptionFilter implements ExceptionFilter {
return response.status(400).json(dbError);
}
if (exception instanceof BadRequest) {
if (exception instanceof BadRequest || exception.getStatus?.() === 400) {
return response.status(400).json({ msg: exception.message });
} else if (exception instanceof Unauthorized) {
} else if (
exception instanceof Unauthorized ||
exception.getStatus?.() === 401
) {
return response.status(401).json({ msg: exception.message });
} else if (exception instanceof Forbidden) {
} else if (
exception instanceof Forbidden ||
exception.getStatus?.() === 403
) {
return response.status(403).json({ msg: exception.message });
} else if (exception instanceof NotFound) {
} else if (
exception instanceof NotFound ||
exception.getStatus?.() === 404
) {
return response.status(404).json({ msg: exception.message });
} else if (exception instanceof InternalServerError) {
} else if (
exception instanceof InternalServerError ||
exception.getStatus?.() === 500
) {
return response.status(500).json({ msg: exception.message });
} else if (exception instanceof NotImplemented) {
} else if (
exception instanceof NotImplemented ||
exception.getStatus?.() === 501
) {
return response.status(501).json({ msg: exception.message });
} else if (exception instanceof AjvError) {
return response

12
packages/nocodb-nest/src/modules/attachments/attachments.controller.ts

@ -13,22 +13,18 @@ import {
UseInterceptors,
} from '@nestjs/common'
import multer from 'multer';
import { FileInterceptor, FilesInterceptor } from '@nestjs/platform-express';
import { OrgUserRoles, ProjectRoles } from 'nocodb-sdk';
import { FilesInterceptor } from '@nestjs/platform-express';
import { AuthGuard } from '@nestjs/passport';
import { NC_ATTACHMENT_FIELD_SIZE } from '../../constants';
import { NcError } from '../../helpers/catchError';
import { UploadAllowedInterceptor } from '../../interceptors/is-upload-allowed/is-upload-allowed.interceptor';
import { ExtractProjectIdMiddleware } from '../../middlewares/extract-project-id/extract-project-id.middleware';
import Noco from '../../Noco';
import { MetaTable } from '../../utils/globals';
import { ExtractProjectIdMiddleware } from '../../middlewares/extract-project-id/extract-project-id.middleware'
import { AttachmentsService } from './attachments.service';
@Controller()
export class AttachmentsController {
constructor(private readonly attachmentsService: AttachmentsService) {}
@UseGuards(ExtractProjectIdMiddleware, AuthGuard('jwt'))
@UseGuards(AuthGuard('jwt'))
@Post(
'/api/v1/db/storage/upload',
// multer({
@ -80,7 +76,7 @@ export class AttachmentsController {
// catchError(uploadViaURL),
// ]
// );
@UseGuards(ExtractProjectIdMiddleware, AuthGuard('jwt'))
@UseGuards(AuthGuard('jwt'))
async uploadViaURL(@Body() body: any, @Query('path') path: string) {
const attachments = await this.attachmentsService.uploadViaURL({
urls: body,

Loading…
Cancel
Save