Skip to content

Commit

Permalink
feat(expressjs): add await for handler
Browse files Browse the repository at this point in the history
  • Loading branch information
pismenskiy authored Mar 26, 2020
1 parent ee707ca commit 6fc00b9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions packages/expressjs/src/main/ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any> {
const boxedJsonRpc = (this.constructor as any).parseRequest(req)
if (!boxedJsonRpc) {
// TODO
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions packages/expressjs/src/test/ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}
}

Expand All @@ -37,7 +37,7 @@ describe('expressjs-json-rpc', () => {
}

@JsonRpcMethod('get-some-error')
getSomeError() {
async getSomeError() {
return new JsonRpcError('Some error', -100000)
}

Expand Down

0 comments on commit 6fc00b9

Please sign in to comment.