Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

add error handling

Kiran Kc02ff4b607d0
diff --git a/apps/web/app/api/links/[linkId]/route.ts b/apps/web/app/api/links/[linkId]/route.ts
index 6a7e221ad1..6f5fa6cd38 100644
--- a/apps/web/app/api/links/[linkId]/route.ts
+++ b/apps/web/app/api/links/[linkId]/route.ts
@@ -81,10 +81,14 @@ export const PUT = withAuth(async ({ req, headers, project, link }) => {
// DELETE /api/links/[linkId] – delete a link
export const DELETE = withAuth(async ({ headers, link }) => {
- // link is guaranteed to exist because if not we will return 404
- const response = await deleteLink(link!);
+ try {
+ // link is guaranteed to exist because if not we will return 404
+ const response = await deleteLink(link!);
- return NextResponse.json(response[0], {
- headers,
- });
+ return NextResponse.json(response[0], {
+ headers,
+ });
+ } catch (err) {
+ return handleAndReturnErrorResponse(err);
+ }
});
diff --git a/apps/web/lib/errors.ts b/apps/web/lib/errors.ts
index 4b34f5a06c..36f780a174 100644
--- a/apps/web/lib/errors.ts
+++ b/apps/web/lib/errors.ts
@@ -75,7 +75,7 @@ export class DubApiError extends Error {
}) {
super(message);
this.code = code;
- this.docUrl = docUrl;
+ this.docUrl = docUrl ?? `${docErrorUrl}#${code}`;
}
}
@@ -137,7 +137,7 @@ export function handleApiError(error: any): ErrorResponse & { status: number } {
error: {
code: error.code,
message: error.message,
- doc_url: error.docUrl || `${docErrorUrl}#${error.code}`,
+ doc_url: error.docUrl,
},
status: errorCodeToHttpStatus[error.code],
};