I am working on a large codebase using express + passport.js. I have not structured the project and I was given a wrong test which does the following:
- deletes a manager account
- then uses the session cookie of the deleted account to make a request
- it expects the server to throw 401 (and instead it gets 503).
I have done some debugging and the exception is thrown when passport is calling deserializeUser (rightfully so it throws UserNotFound because it was deleted) and it is propagated somewhere with this callback done(null, error)
.
Now I want to handle the exception thrown in passport.DeserializeUser but somewhere it is handled already (I coudn’t find where and I am having trouble to do so).
My question is:
- is passport handling exceptions and using response.send() somewhere or can I exclude this and just look for the handler in my codebase?
- How can I handle this exception thrown in deserializeUser? Where will the exception be propagated next?
This is the deserializeUser:
passport.deserializeUser(async (user: User, done: any) => {
let userObj: User
try {
userObj = await UserDAO.getUserByUsername(user.username)
} catch (error) {
return done(null, error)
}
done(null, user)
})