Skip to content

Commit 23d65db

Browse files
committed
refactor(deno-runtime): add catch call to handler
Not really necessary as the current handlers all have a surrounding try/catch block in their implementation, but since it is not built into the contract, this is more future proof
1 parent 297a78f commit 23d65db

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

packages/apps/deno-runtime/mainLoop.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import process from 'node:process';
22

3-
import { JsonRpcError, type SuccessObject } from 'jsonrpc-lite';
3+
import jsonrpc, { JsonRpcError, type SuccessObject } from 'jsonrpc-lite';
44

55
import apiHandler from './handlers/api-handler';
66
import handleApp from './handlers/app/handler';
@@ -21,7 +21,7 @@ type Handlers = {
2121
videoconference: typeof videoConferenceHandler;
2222
outboundCommunication: typeof outboundMessageHandler;
2323
scheduler: typeof handleScheduler;
24-
ping: (request: RequestContext) => 'pong';
24+
ping: (request: RequestContext) => Promise<'pong'>;
2525
};
2626

2727
const COMMAND_PING = '_zPING';
@@ -34,7 +34,7 @@ async function requestRouter({ type, payload }: Messenger.JsonRpcRequest): Promi
3434
videoconference: videoConferenceHandler,
3535
outboundCommunication: outboundMessageHandler,
3636
scheduler: handleScheduler,
37-
ping: (_request) => 'pong',
37+
ping: (_request) => Promise.resolve('pong'),
3838
};
3939

4040
// We're not handling notifications at the moment
@@ -63,7 +63,9 @@ async function requestRouter({ type, payload }: Messenger.JsonRpcRequest): Promi
6363
);
6464
}
6565

66-
const result = await handler(context);
66+
const result = await handler(context).catch((reason) =>
67+
JsonRpcError.internalError({ cause: reason instanceof Error ? reason.toString() : reason }),
68+
);
6769

6870
if (result instanceof JsonRpcError) {
6971
return Messenger.errorResponse({ id, error: result }, context);

0 commit comments

Comments
 (0)