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.

catch and return Plain errors

Steven Tey665703037b87
diff --git a/apps/web/app/api/support/route.ts b/apps/web/app/api/support/route.ts
index 8a070b201f..70fbdee170 100644
--- a/apps/web/app/api/support/route.ts
+++ b/apps/web/app/api/support/route.ts
@@ -14,6 +14,12 @@ export const POST = withSession(async ({ req, session }) => {
await req.json(),
);
+ if (!session.user.email) {
+ return NextResponse.json({
+ error: "Invalid user email",
+ });
+ }
+
let plainCustomerId: string | null = null;
const plainCustomer = await plain.getCustomerByEmail({
@@ -23,7 +29,13 @@ export const POST = withSession(async ({ req, session }) => {
if (plainCustomer.data) {
plainCustomerId = plainCustomer.data.id;
} else {
- const { data } = await upsertPlainCustomer(session.user);
+ const { data, error } = await upsertPlainCustomer(session.user);
+ if (error) {
+ return NextResponse.json({
+ error: error.message,
+ });
+ }
+
if (data) {
plainCustomerId = data.customer.id;
}
diff --git a/apps/web/app/api/support/upload/route.ts b/apps/web/app/api/support/upload/route.ts
index 8cbd51e925..2ff40352b5 100644
--- a/apps/web/app/api/support/upload/route.ts
+++ b/apps/web/app/api/support/upload/route.ts
@@ -5,6 +5,12 @@ import { NextResponse } from "next/server";
// POST /api/support/upload – get a signed URL to upload an attachment
export const GET = withSession(async ({ searchParams, session }) => {
+ if (!session.user.email) {
+ return NextResponse.json({
+ error: "Invalid user email",
+ });
+ }
+
let plainCustomerId: string | null = null;
const plainCustomer = await plain.getCustomerByEmail({
@@ -14,7 +20,14 @@ export const GET = withSession(async ({ searchParams, session }) => {
if (plainCustomer.data) {
plainCustomerId = plainCustomer.data.id;
} else {
- const { data } = await upsertPlainCustomer(session.user);
+ const { data, error } = await upsertPlainCustomer(session.user);
+
+ if (error) {
+ return NextResponse.json({
+ error: error.message,
+ });
+ }
+
if (data) {
plainCustomerId = data.customer.id;
}