Skip to content

Commit 4e690d3

Browse files
committed
fix: use run method and throw error used outside of context
`runSyncAndReturn` was removed from Node.js in nodejs/node#31950
1 parent 51098f1 commit 4e690d3

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/AsyncHttpContext.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,16 @@ export default class AsyncHttpContext {
2626
return new Proxy(this, proxyHandler)
2727
}
2828

29-
public runSyncAndReturn (context, next) {
30-
return this.$context.runSyncAndReturn(context, next)
29+
public run (context, next) {
30+
return this.$context.run(context, next)
3131
}
3232

3333
public get context () {
34-
return this.$context.getStore() || {}
34+
const store = this.$context.getStore()
35+
if (store === undefined) {
36+
throw new Error('AsyncHttpContext cannot be used outside of a request context')
37+
}
38+
return store;
3539
}
3640
}
3741

src/AsyncHttpContextMiddleware.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ export default class AsyncHttpContextMiddleware {
55
}
66

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

0 commit comments

Comments
 (0)