1
I have an express api and would like to develop a function to standardize the customer response.
Code (running the function):
response(200, "Evento adicionado com sucesso!", res)
Scope of function:
function response(code, info, res) {
switch (code) {
case 200:
error = false
case 201:
error = false
case 404:
error = true
case 401:
error = true
case 500:
error = true
}
res.status(code)
return res.send({ error: error, info: info })
}
module.exports = {
response: response
}
The problem
Not giving the answer to the customer. I tested with console.log()
in the client and does not display the response. The request is made normally. What may be happening?
Has not
break
in theircase
...– bfavaretto
kkkkkkk, Bah really forgot bro! It’s that kind has some express functions that can not use break, so did not put. But thanks !
– eduardo meurer
And I only need two assignments, one for
false
and another totrue
, peesquise on thecase
and understand how to use it.– Maniero