Skip to content

Commit

Permalink
[chore] better client errors (#57)
Browse files Browse the repository at this point in the history
* surface errors to client

* Create light-badgers-doubt.md
  • Loading branch information
markflorkowski authored May 12, 2023
1 parent 1a16ab6 commit 336d361
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/light-badgers-doubt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"uploadthing": patch
---

[chore] better client errors
2 changes: 1 addition & 1 deletion packages/uploadthing/src/internal/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ export const buildRequestHandler = <
console.error("[UT] middleware failed to run");
console.error(e);

return { status: 400, message: (e as Error).message };
return { status: 400, message: (e as Error).toString() };
}
};
};
Expand Down
2 changes: 1 addition & 1 deletion packages/uploadthing/src/next/core/approuter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const createNextRouteHandler = <TRouter extends FileRouter>(
});
}

return new Response("Error", {
return new Response(response.message ?? "Unable to upload file.", {
status: response.status,
headers: {
"x-uploadthing-version": UPLOADTHING_VERSION,
Expand Down
2 changes: 1 addition & 1 deletion packages/uploadthing/src/next/core/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ export const createNextPageApiHandler = <TRouter extends FileRouter>(
if (response.status === 200) {
return res.json(response.body);
}
return res.send("Error");
return res.send(response.message ?? "Unable to upload file.");
};
};

1 comment on commit 336d361

@vercel
Copy link

@vercel vercel bot commented on 336d361 May 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.