Skip to content

Commit

Permalink
Update error handling and exception messages
Browse files Browse the repository at this point in the history
  • Loading branch information
wet6123 committed Aug 3, 2024
1 parent 304f21b commit 1e42017
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 79 deletions.
10 changes: 2 additions & 8 deletions backend/src/documents/documents.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down
20 changes: 4 additions & 16 deletions backend/src/files/files.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]}`;
Expand All @@ -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.");
}
}

Expand All @@ -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");
}
}

Expand Down
6 changes: 1 addition & 5 deletions backend/src/intelligence/intelligence.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
5 changes: 1 addition & 4 deletions backend/src/users/users.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
32 changes: 12 additions & 20 deletions backend/src/workspace-documents/workspace-documents.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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 = {};
Expand Down Expand Up @@ -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."
);
}
}

Expand Down Expand Up @@ -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();
Expand Down
8 changes: 3 additions & 5 deletions backend/src/workspace-users/workspace-users.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};
Expand Down
30 changes: 9 additions & 21 deletions backend/src/workspaces/workspaces.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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."
);
}
}

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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 {
Expand All @@ -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({
Expand Down

0 comments on commit 1e42017

Please sign in to comment.