mirror of
https://github.com/geoffsee/open-gsio.git
synced 2025-09-08 22:56:46 +00:00
add top level error handler to the router
This commit is contained in:

committed by
Geoff Seemueller

parent
fa5b7466bc
commit
ffabfd4ce5
@@ -4,6 +4,7 @@ import ServerCoordinator from '@open-gsio/coordinators/src/ServerCoordinatorBun.
|
|||||||
import Router from '@open-gsio/router';
|
import Router from '@open-gsio/router';
|
||||||
import { config } from 'dotenv';
|
import { config } from 'dotenv';
|
||||||
import type { RequestLike } from 'itty-router';
|
import type { RequestLike } from 'itty-router';
|
||||||
|
import { error } from 'itty-router';
|
||||||
|
|
||||||
import { BunSqliteKVNamespace } from '../storage/BunSqliteKVNamespace.ts';
|
import { BunSqliteKVNamespace } from '../storage/BunSqliteKVNamespace.ts';
|
||||||
|
|
||||||
@@ -49,8 +50,7 @@ export default {
|
|||||||
reject(new Error('Request timeout after 5s'));
|
reject(new Error('Request timeout after 5s'));
|
||||||
}, 5000),
|
}, 5000),
|
||||||
);
|
);
|
||||||
|
return await Promise.race([router.fetch(request, env, ctx).catch(error), timeout]);
|
||||||
return await Promise.race([router.fetch(request, env, ctx), timeout]);
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Error handling request:', e);
|
console.error('Error handling request:', e);
|
||||||
return new Response('Server Error', { status: 500 });
|
return new Response('Server Error', { status: 500 });
|
||||||
|
Reference in New Issue
Block a user