@@ -137,7 +137,17 @@ type CallbackWithStatus = Route['callback'] & { status: number }
137
137
async function execute ( foundRoute : Route , req : Request , { statusCode } : Options ) {
138
138
const foundCallback : CallbackWithStatus = await route . resolveCallback ( foundRoute . callback )
139
139
140
+ // return new Response(`<html><body><h1>Error</h1><p>${foundCallback}</p><pre></pre></body></html>`, {
141
+ // headers: {
142
+ // 'Content-Type': 'text/html',
143
+ // 'Access-Control-Allow-Origin': '*',
144
+ // 'Access-Control-Allow-Headers': '*',
145
+ // },
146
+ // status: 500,
147
+ // })
148
+
140
149
const middlewarePayload = await executeMiddleware ( foundRoute )
150
+
141
151
142
152
if (
143
153
middlewarePayload !== null
@@ -239,7 +249,7 @@ async function execute(foundRoute: Route, req: Request, { statusCode }: Options)
239
249
240
250
if ( isObject ( foundCallback ) && foundCallback . status ) {
241
251
if ( foundCallback . status === 401 ) {
242
- const { status, ...rest } = foundCallback
252
+ const { status, ...rest } = await foundCallback
243
253
244
254
return new Response ( JSON . stringify ( rest ) , {
245
255
headers : {
@@ -251,8 +261,22 @@ async function execute(foundRoute: Route, req: Request, { statusCode }: Options)
251
261
} )
252
262
}
253
263
264
+ if ( foundCallback . status === 404 ) {
265
+ const { status, ...rest } = await foundCallback
266
+
267
+ const { errors } = rest
268
+ return new Response ( JSON . stringify ( errors ) , {
269
+ headers : {
270
+ 'Content-Type' : 'application/json' ,
271
+ 'Access-Control-Allow-Origin' : '*' ,
272
+ 'Access-Control-Allow-Headers' : '*' ,
273
+ } ,
274
+ status : 404 ,
275
+ } )
276
+ }
277
+
254
278
if ( foundCallback . status === 403 ) {
255
- const { status, ...rest } = foundCallback
279
+ const { status, ...rest } = await foundCallback
256
280
257
281
return new Response ( JSON . stringify ( rest ) , {
258
282
headers : {
@@ -265,7 +289,7 @@ async function execute(foundRoute: Route, req: Request, { statusCode }: Options)
265
289
}
266
290
267
291
if ( foundCallback . status === 422 ) {
268
- const { status, ...rest } = foundCallback
292
+ const { status, ...rest } = await foundCallback
269
293
270
294
return new Response ( JSON . stringify ( rest ) , {
271
295
headers : {
@@ -278,9 +302,10 @@ async function execute(foundRoute: Route, req: Request, { statusCode }: Options)
278
302
}
279
303
280
304
if ( foundCallback . status === 500 ) {
281
- const { status, ...rest } = foundCallback
305
+ const { status, ...rest } = await foundCallback
282
306
283
- return new Response ( JSON . stringify ( rest ) , {
307
+ const { errors } = rest
308
+ return new Response ( `<html><body><h1>Error</h1><p>${ errors } </p><pre></pre></body></html>` , {
284
309
headers : {
285
310
'Content-Type' : 'application/json' ,
286
311
'Access-Control-Allow-Origin' : '*' ,
0 commit comments