diff --git a/packages/expressjs/src/main/ts/index.ts b/packages/expressjs/src/main/ts/index.ts index a269985..8cf3490 100644 --- a/packages/expressjs/src/main/ts/index.ts +++ b/packages/expressjs/src/main/ts/index.ts @@ -46,8 +46,8 @@ export function JsonRpcMiddleware(): ClassDecorator { const extend: Extender = (base) => { class Extended extends base { - @AsyncMiddleware() - protected middleware(req: Request, res: Response): any { + @AsyncMiddleware + protected async middleware(req: Request, res: Response): Promise { const boxedJsonRpc = (this.constructor as any).parseRequest(req) if (!boxedJsonRpc) { // TODO @@ -64,7 +64,7 @@ export function JsonRpcMiddleware(): ClassDecorator { return } - const result = (this.constructor as any).handleResult(handler.apply(this, params)) + const result = (this.constructor as any).handleResult(await handler.apply(this, params)) const jsonRpcResponse = result instanceof JsonRpcError ? error(id, result) : success(id, result) diff --git a/packages/expressjs/src/test/ts/index.ts b/packages/expressjs/src/test/ts/index.ts index fe36710..29a57f4 100644 --- a/packages/expressjs/src/test/ts/index.ts +++ b/packages/expressjs/src/test/ts/index.ts @@ -27,7 +27,7 @@ describe('expressjs-json-rpc', () => { middleware: any @JsonRpcMethod('test1') - bar(@RpcId() id: string) { + async bar(@RpcId() id: string) { return {foo: 'bar', id} } @@ -37,7 +37,7 @@ describe('expressjs-json-rpc', () => { } @JsonRpcMethod('get-some-error') - getSomeError() { + async getSomeError() { return new JsonRpcError('Some error', -100000) }