fix: improve error log coverage

This commit is contained in:
David Nguyen
2024-03-30 14:00:34 +08:00
parent 369357aadd
commit b436331d7d
8 changed files with 218 additions and 151 deletions

View File

@@ -29,6 +29,8 @@ export const adminRouter = router({
try {
return await findDocuments({ term, page, perPage });
} catch (err) {
console.error(err);
throw new TRPCError({
code: 'BAD_REQUEST',
message: 'We were unable to retrieve the documents. Please try again.',
@@ -44,6 +46,8 @@ export const adminRouter = router({
try {
return await updateUser({ id, name, email, roles });
} catch (err) {
console.error(err);
throw new TRPCError({
code: 'BAD_REQUEST',
message: 'We were unable to retrieve the specified account. Please try again.',
@@ -59,6 +63,8 @@ export const adminRouter = router({
try {
return await updateRecipient({ id, name, email });
} catch (err) {
console.error(err);
throw new TRPCError({
code: 'BAD_REQUEST',
message: 'We were unable to update the recipient provided.',
@@ -79,6 +85,8 @@ export const adminRouter = router({
userId: ctx.user.id,
});
} catch (err) {
console.error(err);
throw new TRPCError({
code: 'BAD_REQUEST',
message: 'We were unable to update the site setting provided.',
@@ -95,6 +103,7 @@ export const adminRouter = router({
return await sealDocument({ documentId: id, isResealing: true });
} catch (err) {
console.log('resealDocument error', err);
throw new TRPCError({
code: 'BAD_REQUEST',
message: 'We were unable to reseal the document provided.',

View File

@@ -16,7 +16,9 @@ export const apiTokenRouter = router({
getTokens: authenticatedProcedure.query(async ({ ctx }) => {
try {
return await getUserTokens({ userId: ctx.user.id });
} catch (e) {
} catch (err) {
console.error(err);
throw new TRPCError({
code: 'BAD_REQUEST',
message: 'We were unable to find your API tokens. Please try again.',
@@ -34,7 +36,9 @@ export const apiTokenRouter = router({
id,
userId: ctx.user.id,
});
} catch (e) {
} catch (err) {
console.error(err);
throw new TRPCError({
code: 'BAD_REQUEST',
message: 'We were unable to find this API token. Please try again.',
@@ -54,7 +58,9 @@ export const apiTokenRouter = router({
tokenName,
expiresIn: expirationDate,
});
} catch (e) {
} catch (err) {
console.error(err);
throw new TRPCError({
code: 'BAD_REQUEST',
message: 'We were unable to create an API token. Please try again.',
@@ -73,7 +79,9 @@ export const apiTokenRouter = router({
teamId,
userId: ctx.user.id,
});
} catch (e) {
} catch (err) {
console.error(err);
throw new TRPCError({
code: 'BAD_REQUEST',
message: 'We were unable to delete this API Token. Please try again.',

View File

@@ -115,6 +115,8 @@ export const documentRouter = router({
requestMetadata: extractNextApiRequestMetadata(ctx.req),
});
} catch (err) {
console.error(err);
if (err instanceof TRPCError) {
throw err;
}
@@ -222,6 +224,7 @@ export const documentRouter = router({
const userId = ctx.user.id;
try {
return await updateTitle({
title,
userId,
@@ -229,6 +232,11 @@ export const documentRouter = router({
documentId,
requestMetadata: extractNextApiRequestMetadata(ctx.req),
});
} catch (err) {
console.error(err);
throw err;
}
}),
setPasswordForDocument: authenticatedProcedure
@@ -347,7 +355,9 @@ export const documentRouter = router({
userId: ctx.user.id,
});
return documents;
} catch (error) {
} catch (err) {
console.error(err);
throw new TRPCError({
code: 'BAD_REQUEST',
message: 'We are unable to search for documents. Please try again later.',

View File

@@ -52,6 +52,7 @@ export const fieldRouter = router({
.mutation(async ({ input, ctx }) => {
const { templateId, fields } = input;
try {
await setFieldsForTemplate({
userId: ctx.user.id,
templateId,
@@ -66,6 +67,11 @@ export const fieldRouter = router({
pageHeight: field.pageHeight,
})),
});
} catch (err) {
console.error(err);
throw err;
}
}),
signFieldWithToken: procedure

View File

@@ -37,6 +37,8 @@ export const profileRouter = router({
...input,
});
} catch (err) {
console.error(err);
throw new TRPCError({
code: 'BAD_REQUEST',
message: 'We were unable to find user security audit logs. Please try again.',
@@ -50,6 +52,8 @@ export const profileRouter = router({
return await getUserById({ id });
} catch (err) {
console.error(err);
throw new TRPCError({
code: 'BAD_REQUEST',
message: 'We were unable to retrieve the specified account. Please try again.',
@@ -108,6 +112,8 @@ export const profileRouter = router({
return { success: true, url: user.url };
} catch (err) {
console.error(err);
const error = AppError.parseError(err);
if (error.code !== AppErrorCode.UNKNOWN_ERROR) {
@@ -135,6 +141,8 @@ export const profileRouter = router({
requestMetadata: extractNextApiRequestMetadata(ctx.req),
});
} catch (err) {
console.error(err);
let message =
'We were unable to update your profile. Please review the information you provided and try again.';
@@ -171,6 +179,8 @@ export const profileRouter = router({
requestMetadata: extractNextApiRequestMetadata(ctx.req),
});
} catch (err) {
console.error(err);
let message = 'We were unable to reset your password. Please try again.';
if (err instanceof Error) {
@@ -192,6 +202,8 @@ export const profileRouter = router({
return await sendConfirmationToken({ email });
} catch (err) {
console.error(err);
let message = 'We were unable to send a confirmation email. Please try again.';
if (err instanceof Error) {
@@ -211,6 +223,8 @@ export const profileRouter = router({
id: ctx.user.id,
});
} catch (err) {
console.error(err);
let message = 'We were unable to delete your account. Please try again.';
if (err instanceof Error) {

View File

@@ -29,6 +29,7 @@ export const singleplayerRouter = router({
createSinglePlayerDocument: procedure
.input(ZCreateSinglePlayerDocumentMutationSchema)
.mutation(async ({ input }) => {
try {
const { signer, fields, documentData, documentName } = input;
const document = await getFile({
@@ -175,5 +176,10 @@ export const singleplayerRouter = router({
});
return token;
} catch (err) {
console.error(err);
throw err;
}
}),
});

View File

@@ -56,6 +56,8 @@ export const templateRouter = router({
recipients: input.recipients,
});
} catch (err) {
console.error(err);
throw new TRPCError({
code: 'BAD_REQUEST',
message: 'We were unable to create this document. Please try again later.',

View File

@@ -21,6 +21,8 @@ export const webhookRouter = router({
try {
return await getWebhooksByUserId(ctx.user.id);
} catch (err) {
console.error(err);
throw new TRPCError({
code: 'BAD_REQUEST',
message: 'We were unable to fetch your webhooks. Please try again later.',
@@ -36,6 +38,8 @@ export const webhookRouter = router({
try {
return await getWebhooksByTeamId(teamId, ctx.user.id);
} catch (err) {
console.error(err);
throw new TRPCError({
code: 'BAD_REQUEST',
message: 'We were unable to fetch your webhooks. Please try again later.',
@@ -55,6 +59,8 @@ export const webhookRouter = router({
teamId,
});
} catch (err) {
console.error(err);
throw new TRPCError({
code: 'BAD_REQUEST',
message: 'We were unable to fetch your webhook. Please try again later.',
@@ -77,6 +83,8 @@ export const webhookRouter = router({
userId: ctx.user.id,
});
} catch (err) {
console.error(err);
throw new TRPCError({
code: 'BAD_REQUEST',
message: 'We were unable to create this webhook. Please try again later.',
@@ -96,6 +104,8 @@ export const webhookRouter = router({
userId: ctx.user.id,
});
} catch (err) {
console.error(err);
throw new TRPCError({
code: 'BAD_REQUEST',
message: 'We were unable to create this webhook. Please try again later.',
@@ -116,6 +126,8 @@ export const webhookRouter = router({
teamId,
});
} catch (err) {
console.error(err);
throw new TRPCError({
code: 'BAD_REQUEST',
message: 'We were unable to create this webhook. Please try again later.',