Skip to content

Commit

Permalink
fix: use run method and throw error used outside of context
Browse files Browse the repository at this point in the history
`runSyncAndReturn` was removed from Node.js in nodejs/node#31950
  • Loading branch information
targos committed Apr 24, 2020
1 parent 51098f1 commit 4e690d3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions src/AsyncHttpContext.ts
Expand Up @@ -26,12 +26,16 @@ export default class AsyncHttpContext {
return new Proxy(this, proxyHandler)
}

public runSyncAndReturn (context, next) {
return this.$context.runSyncAndReturn(context, next)
public run (context, next) {
return this.$context.run(context, next)
}

public get context () {
return this.$context.getStore() || {}
const store = this.$context.getStore()
if (store === undefined) {
throw new Error('AsyncHttpContext cannot be used outside of a request context')
}
return store;
}
}

2 changes: 1 addition & 1 deletion src/AsyncHttpContextMiddleware.ts
Expand Up @@ -5,6 +5,6 @@ export default class AsyncHttpContextMiddleware {
}

public async handle (ctx: HttpContextContract, next: () => Promise<void>) {
return this.$context.runSyncAndReturn(ctx, next)
return this.$context.run(ctx, next)
}
}

0 comments on commit 4e690d3

Please sign in to comment.