0
I’m making an application and wanted after giving a request, that the API bring an image of this website as an answer. For example, in giving error 404, I would like you to bring that.
How can I do?
I currently have a method of this:
app.use((req, res, next) => {
const error = new Error('Não há nada aqui :c');
error.status = 404;
next(error);
});
app.use((error, req, res, next) => {
res.status(error.status || 500);
res.json({
error: {
mensagem: error.message
}
})
});
Have you looked at the documentation of response object of Expressjs? There is a method for sending files that can serve what you need.
– Gustavo Sampaio
@Gustavosampaio already looked yes face, but for being new in this world, I could not find a right answer!
– Lucas Brito