Skip to content

Instructions for customising REST errorHandler #688

Closed

Description

@bajtos

We need to document instructions for setting a custom errorHandler via server/config.local.js.

strongloop/strong-remoting#114 implements support for errorHandler option, #337 will hopefully modify loopback.rest to pass app.get('remoting').rest options to the REST handler.

Activity

  1. bajtos commented on Nov 5, 2014

    @bajtos
    MemberAuthor

    I believe this should work with the current loopback version:

    // server/config.local.json
    module.exports = {
      remoting: {
        errorHandler: {
          handler: function(err, req, res, next) {
            // custom error handling logic
            // call `next()` to fall back to the default error handler
          }
        }
      }
    };

    On a related note, error stack traces can be disabled via server/config.json like this:

    {
      "remoting": {
        "errorHandler": {
          "disableStackTrace": true
        }
      }
    }
  2. 26 remaining items

  3. assigned and unassigned on Jan 20, 2015
  4. crandmck commented on Jan 20, 2015

    @crandmck
    Contributor

    @bajtos Please review and close if it looks OK.

  5. bajtos commented on Jan 21, 2015

    @bajtos
    MemberAuthor

    LGTM.

  6. jrschumacher commented on Mar 8, 2015

    @jrschumacher

    There should be a link to the customizing REST error handling on http://docs.strongloop.com/display/public/LB/Defining+middleware

  7. simoami commented on Oct 16, 2015

    @simoami

    just for the sake of understanding, you have two error handlers, one referenced in middleware.json and another one in strong-remoting. when does the error handler defined in middleware.json kick in? I tried defining a custom one but it never kicked in. To test, I created a custom API route that explicitly returns an error on callback cb(err). I also used a mix of throw err and 1/0 to see if I could trigger the custom error middleware but no luck there. ps I defined the error handler with 4 arguments as express expects.

  8. crandmck commented on Oct 16, 2015

    @crandmck
    Contributor

    @simoami You should ask your question on the Google Group. No one will notice it here in a closed GH issue.
    PS. If I knew the answer, I would tell you, but I don't :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions