(request: Request, env: Env, ctx: ExecutionContext)
| 269 | |
| 270 | export default { |
| 271 | async fetch(request: Request, env: Env, ctx: ExecutionContext) { |
| 272 | try { |
| 273 | return await app.fetch(request, env, ctx); |
| 274 | } catch (err) { |
| 275 | console.error(err); |
| 276 | const e = err as Error; |
| 277 | console.log(`Ouch, that error hurt so much Sentry couldn't catch it`); |
| 278 | console.log(e.stack); |
| 279 | let errorCode = 500; |
| 280 | if (e.name === 'AbortError') { |
| 281 | errorCode = 504; |
| 282 | } |
| 283 | /* We return it as a 200 so embedded applications can display the error */ |
| 284 | if (request.headers.get('user-agent')?.match(embeddingClientRegex)) { |
| 285 | errorCode = 200; |
| 286 | } |
| 287 | const branding = getBranding(request); |
| 288 | |
| 289 | return new Response( |
| 290 | e.name === 'AbortError' |
| 291 | ? Strings.TIMEOUT_ERROR_HTML.format({ brandingName: branding.name }) |
| 292 | : Strings.ERROR_HTML.format({ brandingName: branding.name }), |
| 293 | { |
| 294 | headers: { |
| 295 | ...Constants.RESPONSE_HEADERS, |
| 296 | 'content-type': 'text/html;charset=utf-8', |
| 297 | 'cache-control': noCache |
| 298 | }, |
| 299 | status: errorCode |
| 300 | } |
| 301 | ); |
| 302 | } |
| 303 | } |
| 304 | }; |
no test coverage detected