Skip to content

Commit 4d50415

Browse files
committed
fix(reactive-rpc): 🐛 handle route handler async errors
1 parent 00680d7 commit 4d50415

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/reactive-rpc/server/http1/Http1Server.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {Codecs} from '../../../json-pack/codecs/Codecs';
1515
import {RpcMessageCodecs} from '../../common/codec/RpcMessageCodecs';
1616
import {NullObject} from '../../../util/NullObject';
1717

18-
export type Http1Handler = (ctx: Http1ConnectionContext) => void;
18+
export type Http1Handler = (ctx: Http1ConnectionContext) => void | Promise<void>;
1919
export type Http1NotFoundHandler = (res: http.ServerResponse, req: http.IncomingMessage) => void;
2020
export type Http1InternalErrorHandler = (error: unknown, res: http.ServerResponse, req: http.IncomingMessage) => void;
2121

@@ -115,7 +115,7 @@ export class Http1Server implements Printable {
115115
this.httpRouter.add(route, match);
116116
}
117117

118-
private readonly onRequest = (req: http.IncomingMessage, res: http.ServerResponse) => {
118+
private readonly onRequest = async (req: http.IncomingMessage, res: http.ServerResponse) => {
119119
try {
120120
res.sendDate = false;
121121
const url = req.url ?? '';
@@ -135,9 +135,9 @@ export class Http1Server implements Printable {
135135
const codecs = this.codecs;
136136
const ip = this.findIp(req);
137137
const token = this.findToken(req);
138-
const ctx = new Http1ConnectionContext(req, res, path, query, ip, token, match.params, new NullObject(), codecs.value.json, codecs.value.json, codecs.messages.jsonRpc2);
138+
const ctx = new Http1ConnectionContext(req, res, path, query, ip, token, match.params, new NullObject(), codecs.value.json, codecs.value.json, codecs.messages.compact);
139139
const handler = match.data.handler;
140-
handler(ctx);
140+
await handler(ctx);
141141
} catch (error) {
142142
this.oninternalerror(error, res, req);
143143
}

0 commit comments

Comments
 (0)