From fdf9df243b6ed2f912df5600748a572f3826f1fa Mon Sep 17 00:00:00 2001 From: m5r Date: Sun, 1 Aug 2021 19:21:49 +0800 Subject: [PATCH] fix error boundary error handling --- app/api/ddd.ts | 10 +++++----- app/core/layouts/layout/index.tsx | 14 +++++++------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/app/api/ddd.ts b/app/api/ddd.ts index 2806ae4..5fe8608 100644 --- a/app/api/ddd.ts +++ b/app/api/ddd.ts @@ -4,14 +4,14 @@ import db from "db"; import twilio from "twilio"; export default async function ddd(req: BlitzApiRequest, res: BlitzApiResponse) { - /*await Promise.all([ + await Promise.all([ db.message.deleteMany(), db.phoneCall.deleteMany(), db.phoneNumber.deleteMany(), db.customer.deleteMany(), ]); - await db.user.deleteMany();*/ + await db.user.deleteMany(); const accountSid = "ACa886d066be0832990d1cf43fb1d53362"; const authToken = "8696a59a64b94bb4eba3548ed815953b"; /*const ddd = await twilio(accountSid, authToken) @@ -32,11 +32,11 @@ export default async function ddd(req: BlitzApiRequest, res: BlitzApiResponse) { console.log(error.details); // console.log(JSON.stringify(Object.keys(error))); }*/ - const ddd = await twilio(accountSid, authToken).messages.create({ + /*const ddd = await twilio(accountSid, authToken).messages.create({ body: "content", to: "+33757592025", from: "+33757592722", - }); + });*/ - res.status(200).send(ddd); + res.status(200).end(); } diff --git a/app/core/layouts/layout/index.tsx b/app/core/layouts/layout/index.tsx index aea1ba5..1f9bb8a 100644 --- a/app/core/layouts/layout/index.tsx +++ b/app/core/layouts/layout/index.tsx @@ -60,12 +60,12 @@ type ErrorBoundaryState = errorMessage: string; }; -const blitzErrorNames = [ - RedirectError.name, - AuthenticationError.name, - AuthorizationError.name, - CSRFTokenMismatchError.name, - NotFoundError.name, +const blitzErrors = [ + RedirectError, + AuthenticationError, + AuthorizationError, + CSRFTokenMismatchError, + NotFoundError, ]; const ErrorBoundary = withRouter( @@ -83,7 +83,7 @@ const ErrorBoundary = withRouter( public componentDidCatch(error: Error, errorInfo: ErrorInfo) { logger.error(error, errorInfo.componentStack); - if (blitzErrorNames.includes(error.name)) { + if (blitzErrors.some((blitzError) => error instanceof blitzError)) { // let Blitz ErrorBoundary handle this one throw error; }