Skip to content

Commit

Permalink
chore: improve error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
psanders committed Dec 28, 2024
1 parent f01e634 commit ec5f6b1
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 73 deletions.
4 changes: 2 additions & 2 deletions mods/apiserver/src/utils/createCheckNumberPreconditions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import { Prisma } from "../core/db";

function createCheckNumberPreconditions(prisma: Prisma) {
return async function checkNumberPreconditions({ appRef, accessKeyId }) {
// You can have a Number without an Application but it must exist
if (!appRef) {
// Not needed to check for the precondition
return;
}

Expand All @@ -33,7 +33,7 @@ function createCheckNumberPreconditions(prisma: Prisma) {

if (!app) {
throw new GrpcError(
status.NOT_FOUND,
status.INVALID_ARGUMENT,
"Application not found for ref: " + appRef
);
}
Expand Down
3 changes: 1 addition & 2 deletions mods/common/src/errors/PrismaErrorEnum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
*/
enum PrismaErrorEnum {
RECORD_ALREADY_EXISTS = "P2002",
RECORD_NOT_FOUND = "P2025",
FAILED_PRECONDITION = "P2003"
RECORD_NOT_FOUND = "P2025"
}

export { PrismaErrorEnum };
10 changes: 1 addition & 9 deletions mods/common/src/errors/handleError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,6 @@ function handleError(
"not found error"
);
break;
case PrismaErrorEnum.FAILED_PRECONDITION:
case grpc.status.FAILED_PRECONDITION:
logAndCallback(
status.FAILED_PRECONDITION,
"Failed precondition error (e.g., missing dependency)",
"failed precondition error"
);
break;
case grpc.status.PERMISSION_DENIED:
logAndCallback(
status.PERMISSION_DENIED,
Expand All @@ -96,7 +88,7 @@ function handleError(
case grpc.status.INVALID_ARGUMENT:
logAndCallback(
status.INVALID_ARGUMENT,
message ?? "Your request has invalid arguments",
message ?? "Your request has one or more invalid arguments",
"invalid argument error"
);
break;
Expand Down
Loading

0 comments on commit ec5f6b1

Please sign in to comment.