mesaugat / express-api-es6-starter

Build APIs with Express.js in no time using ES6/ES7/ESNext goodness.

Home Page:https://express-api-es6-starter.herokuapp.com/api-docs/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Show error message on 500

duard opened this issue · comments

How can I show that error message on console in my return ?

2017-12-16T11:03:36.598Z - error: Error: ER_NO_SUCH_TABLE: Table 'sigpharmaDB1.tipos_medicamentos' doesn't exist

screenshot from 2017-12-16 09-04-07

This is exactly how it should work. Brother you should not tell the public facing API that your database does not exist. It is a security risk.

This message should be only displayed to the developers which you can get from the logs or the console. Thus, every time an internal error occurs the API sends a 500, Server Error. You will have to check your logs and fix the problem.

@mesaugat thanks for repply ! Its only an example of type of error I want to show ... of course I will not show it in production ;-) and I will show it only in development mode !

This is the line returning 500 error response. You need to change a few lines in this file to show that error message in the response. https://github.com/mesaugat/express-api-es6-starter/blob/master/src/utils/buildError.js#L34-L38