chore: Couple fixes to improve error reporting (#16895)

* chore: Couple fixes to improve error reporting

* tweak: Fix error message

* refactor: Use findUniqueOrThrow instead of guard

* fix: Broken test, missing ID - suspect it passes because only one record exists

* chore: Minor refactor to split ZodEffect from ZodType

* fix: Satify typescript
This commit is contained in:
Alex van Andel authored and GitHub committed 2024-10-01 09:18:51 -03:00
1 parent 4b6a389212
commit a95729f4a1
9 files changed
+31 -28

No files matched your search

+6 -5
View File
@@ -17,12 +17,13 @@ export function defaultResponder<T>(f: Handle<T>) {
return res.json(result);
}
} catch (err) {
console.error(err);
const error = getServerErrorFromUnknown(err);
// dynamic import of Sentry so it's only loaded when something goes wrong.
const captureException = (await import("@sentry/nextjs")).captureException;
captureException(err);
// return API route response
// we don't want to report Bad Request errors to Sentry / console
if (!(error.statusCode >= 400 && error.statusCode < 500)) {
console.error(err);
const captureException = (await import("@sentry/nextjs")).captureException;
captureException(err);
}
return res
.status(error.statusCode)
.json({ message: error.message, url: error.url, method: error.method });
@@ -28,7 +28,6 @@ function parseZodErrorIssues(issues: ZodIssue[]): string {
export function getServerErrorFromUnknown(cause: unknown): HttpError {
if (isZodError(cause)) {
console.log("cause", cause);
return new HttpError({
statusCode: 400,
message: parseZodErrorIssues(cause.issues),