You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ctx.debug('`this.next` called more than once within the same middleware function but was ignored due to being in an Error flow. %o',{ middlewareName,error: ctx.error})
161
-
}else{
162
-
thrownewError(`Error running proxy middleware: Cannot call this.next() more than once in the same middleware function. Doing so can cause unintended issues.`)
160
+
consterror=newError('Error running proxy middleware: Detected `this.next()` was called more than once in the same middleware function. This can cause unintended issues and may indicate an error in your middleware logic or configuration.')
161
+
162
+
if(ctx.error){
163
+
error.message=error.message+=`\nThis middleware invocation previously encountered an error which may be related: ${ctx.error}`
Copy file name to clipboardExpand all lines: packages/proxy/test/unit/http/response-middleware.spec.ts
+44-22Lines changed: 44 additions & 22 deletions
Original file line number
Diff line number
Diff line change
@@ -31,33 +31,55 @@ describe('http/response-middleware', function () {
31
31
])
32
32
})
33
33
34
-
it('errors if this.next() is called more than once in the same middleware',function(done){
35
-
constmiddleware=function(){
36
-
this.next()
37
-
this.next()
38
-
}
34
+
describe('multiple this.next invocations',()=>{
35
+
context('within the same middleware',()=>{
36
+
it('throws an error',function(done){
37
+
constmiddleware=function(){
38
+
this.next()
39
+
this.next()
40
+
}
41
+
42
+
testMiddleware([middleware],{
43
+
onError(err){
44
+
expect(err.message).to.equal('Error running proxy middleware: Detected `this.next()` was called more than once in the same middleware function. This can cause unintended issues and may indicate an error in your middleware logic or configuration.')
45
+
46
+
done()
47
+
},
48
+
})
49
+
})
39
50
40
-
testMiddleware([middleware],{
41
-
onError(err){
42
-
expect(err.message).to.equal('Error running proxy middleware: Cannot call this.next() more than once in the same middleware function. Doing so can cause unintended issues.')
51
+
it('includes a previous context error in error message if one exists',(done)=>{
52
+
constmiddleware=function(){
53
+
this.next()
54
+
this.next()
55
+
}
43
56
44
-
done()
45
-
},
57
+
testMiddleware([middleware],{
58
+
error: newError('previous error'),
59
+
onError(err){
60
+
expect(err.message).to.contain('This middleware invocation previously encountered an error which may be related: Error: previous error')
61
+
62
+
done()
63
+
},
64
+
})
65
+
})
46
66
})
47
-
})
48
67
49
-
it('does not error if this.next() is called more than once in different middleware',function(){
0 commit comments