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
Hey , any recommendations on how to do the following pattern in a route handler, hopefully the pseudo code makes sense:
(req, res, next) => {
loadUser(req)
.andThen(validateUser)
.andThen(lookupCache) // <-- if lookupCache actually finds a result in the cache, we want to skip straight to the match() and return a response
.andThen(validateOptions)
.andThen(doSomethingExpensive)
.andThen(putInCache)
.match(result=>{
res.send(200,{status:"ok",result})
},err=>{
res.send(400,{status:"notok",error:err.message});
})
}
Basically.. I want to short circuit the pipeline if lookupCache finds a result, but continue otherwise.
The only way I can see to do it without breaking this out into two pipelines.. is to return a special error and handle that in the error case..
Otherwise this is kinda what i'm doing now.. but it feels ugly somehow..
Hey , any recommendations on how to do the following pattern in a route handler, hopefully the pseudo code makes sense:
Basically.. I want to short circuit the pipeline if
lookupCache
finds a result, but continue otherwise.The only way I can see to do it without breaking this out into two pipelines.. is to return a special error and handle that in the error case..
Otherwise this is kinda what i'm doing now.. but it feels ugly somehow..
it feels ugly because i'm doing the
res.send
part in multiple places, when I just want to handle it in one.match
call..The text was updated successfully, but these errors were encountered: