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

Asked

Viewed 30 times

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 I’m doing wrong?

The errorHandler only serves for 404 errors?

  • Can you explain the question further? What loopback, the code that generated this error, a live example on https://c9.io/ or something that helps us understand your problem...

  • @Sergio loopback is a framework to generate Rest API with nodejs. More information here: http://loopback.io/. The terms I used are all used in the framework, it may seem that the question is incomplete but it is not..

  • Okay, gave +1. If you have time soon I’ll take a look and see if I can help. In the meantime, if you have a minute: http://answall.com/edit-tag-wiki/3708

  • @Sergio I will add more information about the tag as soon as I get home.

  • You managed to solve the problem?

  • 1

    @Sergio Yes, I will post an answer.

Show 1 more comment

1 answer

1

Setting errors in Loopback is done through 2 files: config.json and middleware.json.

Adding the stack (detailed error description) to Loopback works as follows:

The archive server/config.json:

  1. For type 500 errors only.
  2. Works only if the environment variable NODE_ENV is different from "Production", since for production the stack is removed (which makes perfect sense).
  3. To disable the stack in other environments, simply edit the property errorHandler:
"errorHandler": {
    "disableStackTrace": true
}

The archive server/middleware.json for other types of errors:

  1. Deactivates/Activates in any environment, including the production environment since they are not deactivated automatically as with type 500 errors.
  2. To disable errors, simply add the following property:
"final:after": {
    "loopback#errorHandler": {
        "params": {
            "includeStack": false
        }
    }
}

To separate the settings of each environment, just create the files with the name of the respective environment, for example, a project with 2 environments: Design and Production.

Just create the middleware.production.json and config.production.json when the environment variable NODE_ENV is equal to production, Loopback will automatically load the correct settings file.

  • I’m still beginner in Loopback so I won’t choose my own answer as right not to induce anyone to mistakes, but so far it worked and I haven’t found anything to indicate otherwise.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.