The configuration of errors in Loopback is done through 2 files: config.json and middleware.json.
Adding the stack (detailed description of the error) in Loopback works as follows:
The file server / config.json :
Only for type 500 errors.
It works only if the environment variable NODE_ENV
is different from "production", since for production the stack is removed (which makes sense).
To disable the stack in other environments, just edit the errorHandler
property:
"errorHandler": {
"disableStackTrace": true
}
The server / middleware.json file for other types of errors:
Disables / activates in any environment, including the production environment, since they are not automatically disabled as is the case with type 500 errors.
To disable errors, simply add the following property:
"final:after": {
"loopback#errorHandler": {
"params": {
"includeStack": false
}
}
}
To separate the settings of each environment, simply create the files with the name of the respective environment, for example, a project with 2 environments: developer and production.
Just create middleware.production.json
and config.production.json
that when the environment variable NODE_ENV
is equal to production
, Loopback will automatically load the correct settings file.