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
There are examples in the documentation that show that it is not necessary to return a result of the next middleware. If the developers follow this example for writing packages, then it will be impossible to do this things:
app.use(async(ctx,next)=>{constresult=awaitnext();if(resultinstanceofCustomError){ctx.body="something wrong";ctx.status=500;return;}if(!result&&typeofresult==="object"){ctx.body=result;// response with json}})app.use(async(ctx,next)=>{// example code from external packageawaitnext();// the result is lost});app.use(asyncctx=>{if(ctx.request.charset!=='utf-8')// some logicreturnnewCustomError();return{ok: true}});
Actually, I see this use case as extremely convenient. Why not allow something to be returned for processing? And, for example, consider it as the body of the response. It doesn't matter whether it is a string, an object or a stream, just treat it as a response.
Checklist
I have searched through GitHub issues for similar issues.
I have completely read through the README and documentation.
The text was updated successfully, but these errors were encountered:
zkulbeda
changed the title
[feat] Prefer returning next middleware's result in documentation examples
[feat] Prefer returning the next middleware's result in the documentation examples
Nov 12, 2022
There are examples in the documentation that show that it is not necessary to return a result of the next middleware. If the developers follow this example for writing packages, then it will be impossible to do this things:
Actually, I see this use case as extremely convenient. Why not allow something to be returned for processing? And, for example, consider it as the body of the response. It doesn't matter whether it is a string, an object or a stream, just treat it as a response.
Checklist
The text was updated successfully, but these errors were encountered: