From 1e42017f2ff48ba778390ae6647001104cd745bb Mon Sep 17 00:00:00 2001 From: JunSeong Date: Sat, 3 Aug 2024 12:16:56 +0900 Subject: [PATCH] Update error handling and exception messages --- backend/src/documents/documents.service.ts | 10 ++---- backend/src/files/files.service.ts | 20 +++--------- .../src/intelligence/intelligence.service.ts | 6 +--- backend/src/users/users.service.ts | 5 +-- .../workspace-documents.service.ts | 32 +++++++------------ .../workspace-users.service.ts | 8 ++--- backend/src/workspaces/workspaces.service.ts | 30 ++++++----------- 7 files changed, 32 insertions(+), 79 deletions(-) diff --git a/backend/src/documents/documents.service.ts b/backend/src/documents/documents.service.ts index 2b251cbc..dec88286 100644 --- a/backend/src/documents/documents.service.ts +++ b/backend/src/documents/documents.service.ts @@ -31,10 +31,7 @@ export class DocumentsService { throw new Error(); } } catch (e) { - throw new UnauthorizedException("Unauthorized", { - cause: new Error(), - description: "Invalid sharing token", - }); + throw new UnauthorizedException("Invalid sharing token"); } let document: Document; @@ -46,10 +43,7 @@ export class DocumentsService { }, }); } catch (e) { - throw new NotFoundException("Not found", { - cause: new Error(), - description: "Document not found", - }); + throw new NotFoundException("Document not found"); } return { diff --git a/backend/src/files/files.service.ts b/backend/src/files/files.service.ts index 01c0678b..6c378d59 100644 --- a/backend/src/files/files.service.ts +++ b/backend/src/files/files.service.ts @@ -46,17 +46,11 @@ export class FilesService { }, }); } catch (e) { - throw new UnauthorizedException("Unauthorized", { - cause: new Error(), - description: "Client unauthorized.", - }); + throw new UnauthorizedException("Client unauthorized."); } if (contentLength > 10_000_000) { - throw new UnprocessableEntityException("Unprocessable Entity", { - cause: new Error(), - description: "Content length too long.", - }); + throw new UnprocessableEntityException("Content length too long."); } const fileKey = `${workspace.slug}-${generateRandomKey()}.${contentType.split("/")[1]}`; @@ -81,10 +75,7 @@ export class FilesService { }); return getSignedUrl(this.s3Client, command, { expiresIn: 3600 }); } catch (e) { - throw new NotFoundException("Not found", { - cause: new Error(), - description: "File not found.", - }); + throw new NotFoundException("File not found."); } } @@ -101,10 +92,7 @@ export class FilesService { case "pdf": return this.exportToPdf(content, fileName); default: - throw new BadRequestException("Bad request", { - cause: new Error(), - description: "Invalid export type", - }); + throw new BadRequestException("Invalid export type"); } } diff --git a/backend/src/intelligence/intelligence.service.ts b/backend/src/intelligence/intelligence.service.ts index ac12db17..ceb1bfcc 100644 --- a/backend/src/intelligence/intelligence.service.ts +++ b/backend/src/intelligence/intelligence.service.ts @@ -25,11 +25,7 @@ export class IntelligenceService { }; const selectedPrompt = promptTemplates[feature]; - if (!selectedPrompt) - throw new NotFoundException("Not found", { - cause: new Error(), - description: "Feature not found", - }); + if (!selectedPrompt) throw new NotFoundException("Feature not found"); return selectedPrompt; } diff --git a/backend/src/users/users.service.ts b/backend/src/users/users.service.ts index 2fdae458..edc1fce6 100644 --- a/backend/src/users/users.service.ts +++ b/backend/src/users/users.service.ts @@ -74,10 +74,7 @@ export class UsersService { const { conflict } = await this.checkService.checkNameConflict(nickname); if (conflict) { - throw new ConflictException("Conflict", { - cause: new Error(), - description: "The nickname conflicts.", - }); + throw new ConflictException("The nickname conflicts."); } await this.prismaService.user.update({ diff --git a/backend/src/workspace-documents/workspace-documents.service.ts b/backend/src/workspace-documents/workspace-documents.service.ts index 82b3b391..444b3333 100644 --- a/backend/src/workspace-documents/workspace-documents.service.ts +++ b/backend/src/workspace-documents/workspace-documents.service.ts @@ -26,11 +26,9 @@ export class WorkspaceDocumentsService { }, }); } catch (e) { - throw new NotFoundException("Not found", { - cause: new Error(), - description: - "The workspace does not exist, or the user lacks the appropriate permissions.", - }); + throw new NotFoundException( + "The workspace does not exist, or the user lacks the appropriate permissions." + ); } return this.prismaService.document.create({ @@ -56,11 +54,9 @@ export class WorkspaceDocumentsService { }, }); } catch (e) { - throw new NotFoundException("Not found", { - cause: new Error(), - description: - "The workspace does not exist, or the user lacks the appropriate permissions.", - }); + throw new NotFoundException( + "The workspace does not exist, or the user lacks the appropriate permissions." + ); } const additionalOptions: Prisma.DocumentFindManyArgs = {}; @@ -126,11 +122,9 @@ export class WorkspaceDocumentsService { }); return document; } catch (e) { - throw new NotFoundException("Not found", { - cause: new Error(), - description: - "The workspace or document does not exist, or the user lacks the appropriate permissions.", - }); + throw new NotFoundException( + "The workspace or document does not exist, or the user lacks the appropriate permissions." + ); } } @@ -158,11 +152,9 @@ export class WorkspaceDocumentsService { }, }); } catch (e) { - throw new NotFoundException("Not found", { - cause: new Error(), - description: - "The workspace or document does not exist, or the user lacks the appropriate permissions.", - }); + throw new NotFoundException( + "The workspace or document does not exist, or the user lacks the appropriate permissions." + ); } const token = generateRandomKey(); diff --git a/backend/src/workspace-users/workspace-users.service.ts b/backend/src/workspace-users/workspace-users.service.ts index bdffe763..dd2ff0bc 100644 --- a/backend/src/workspace-users/workspace-users.service.ts +++ b/backend/src/workspace-users/workspace-users.service.ts @@ -21,11 +21,9 @@ export class WorkspaceUsersService { }, }); } catch (e) { - throw new NotFoundException("Not found", { - cause: new Error(), - description: - "The workspace does not exist, or the user lacks the appropriate permissions.", - }); + throw new NotFoundException( + "The workspace does not exist, or the user lacks the appropriate permissions." + ); } const additionalOptions: Prisma.UserFindManyArgs = {}; diff --git a/backend/src/workspaces/workspaces.service.ts b/backend/src/workspaces/workspaces.service.ts index 14eddd51..8c3f39cf 100644 --- a/backend/src/workspaces/workspaces.service.ts +++ b/backend/src/workspaces/workspaces.service.ts @@ -25,10 +25,7 @@ export class WorkspacesService { const { conflict } = await this.checkService.checkNameConflict(title); if (conflict) { - throw new ConflictException("Conflict", { - cause: new Error(), - description: "Workspace title is already in use.", - }); + throw new ConflictException("Workspace title is already in use."); } const workspace = await this.prismaService.workspace.create({ @@ -66,10 +63,9 @@ export class WorkspacesService { return foundWorkspace; } catch (e) { - throw new NotFoundException("Not found", { - cause: new Error(), - description: "Workspace not found, or the user lacks the appropriate permissions.", - }); + throw new NotFoundException( + "Workspace not found, or the user lacks the appropriate permissions." + ); } } @@ -120,11 +116,9 @@ export class WorkspacesService { }, }); } catch (e) { - throw new NotFoundException("Not found", { - cause: new Error(), - description: - "Worksapce does not exist, or the user lacks the appropriate permissions.", - }); + throw new NotFoundException( + "Worksapce does not exist, or the user lacks the appropriate permissions." + ); } const token = generateRandomKey(); @@ -162,10 +156,7 @@ export class WorkspacesService { throw new Error(); } } catch (err) { - throw new UnauthorizedException("Unauthorized", { - cause: new Error(), - description: "Invitation token is invalid or expired.", - }); + throw new UnauthorizedException("Invitation token is invalid or expired."); } try { @@ -175,10 +166,7 @@ export class WorkspacesService { }, }); } catch (e) { - throw new NotFoundException("Not found", { - cause: new Error(), - description: "The workspace is deleted.", - }); + throw new NotFoundException("The workspace is deleted."); } const userWorkspace = await this.prismaService.userWorkspace.findFirst({