Kaynağa Gözat

prevent internal errors passing through api, improve unknown error messaging

Aneurin Barker Snook 1 yıl önce
ebeveyn
işleme
f482ad11b3
2 değiştirilmiş dosya ile 3 ekleme ve 3 silme
  1. 2 2
      src/http.ts
  2. 1 1
      web/src/components/Notice.tsx

+ 2 - 2
src/http.ts

@@ -63,10 +63,10 @@ function createExpress(ctx: Context, staticsPath?: string) {
 
   // Add middleware to handle any errors forwarded from previous handlers via `next(err)`
   const catchError: ErrorRequestHandler = (err, req, res, next) => {
+    ctx.log.error(err)
     if (!res.headersSent) {
-      http.internalServerError(res, next, { reason: (err as Error).message })
+      http.internalServerError(res, next)
     }
-    ctx.log.error(err)
   }
   app.use(catchError)
 

+ 1 - 1
web/src/components/Notice.tsx

@@ -11,7 +11,7 @@ export default function Notice({ className = '', error, ...props }: PropsWithChi
   if (error?.name === 'RequestError') {
     let message = ''
     const re = error as RequestError
-    if (re.data) {
+    if (re.data && Object.keys(re.data).length > 0) {
       if (re.data.param && re.data.reason) message = `Error in ${re.data.param}: ${re.data.reason}`
       else if (re.data.reason) message = `Error: ${re.data.reason}`
     } else message = `Error: ${re.message}`