The stack property is not removed from the Error object when includeStack is equal to false

1

The stack property is not removed from the Error object when includeStack is equal to false :

"final:after": {
    "loopback#errorHandler": {
        "params": {
            "includeStack": false
        }
    }
}

Even with disableStackTrace equal to true in config.json:

"errorHandler": {
    "disableStackTrace": true
}

What am I doing wrong?

Does errorHandler only serve 404 errors?

    
asked by anonymous 12.10.2015 / 20:09

1 answer

1

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.

        
    24.10.2015 / 13:10