Avoid concatenating requests when redirecting multiple times in a row
So, I am working in an Express application and am experiencing strange behavior.
I am showing error messages when something is wrong.
/ app / edit / username? E = Error1
It seems that after two errors in the line, the requests are merged somehow:
app / edit / username? E = Error1? E = Error2
I would like this to happen and only display error 2:
app / edit / username? E = Error2
I am using express redirect:
return res.redirect('/app/edit/' + username + '?e=' + error
Any idea on what might be going on?
Thanks a lot in advance and have a nice weekend!
Pablo
edit: part of the function:
User.findByIdAndUpdate(id, update, function (err, user) {
if (err) {
var error = dbErrorHandler(err)
return res.redirect('/app/editar/' + username + '?e=' + error)
}
return res.redirect('/app/editar/' + username + '/?suc=upsuccess')
})
and here is the dbErrorHandler:
function dbErrorHandler(err) {
console.log('There is been an error' + err)
if (String(err).indexOf('email_1') !== -1)
return 'eexists'
return 'unknown'
}
More advice regarding my code is very welcome.
+3
source to share
No one has answered this question yet
Check out similar questions: