Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use run method and throw error used outside of context #1

Merged
merged 1 commit into from
Apr 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/AsyncHttpContext.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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)
}
}