Skip to content

NotFound handler does not run internal handlers #708

Closed

Description

@DonutEspresso

I had a use case where I was trying to render a 404 page directly in the NotFound event handler, which was causing some issues. There appears to be some internal handlers that set up some initial state, and the NotFound event was not running through those internal handlers.

In my specific case, req.params was not being given an initial value, so attempting to manually invoke common handler from within the NotFound handler was causing all sorts of issues. For example, restify.queryParser and restify.bodyParser expect req.params to be initialized, so manually invoking them caused Restify to blow up.

I eventually resolved the issue by redirecting the request to a known 404 handler, which would then invoke the internal and common handler stack as expected. I suspect this was a design decision, to have the NotFound handler skip any internal handlers. This makes a lot of sense for lean REST API services, but for a more complex web app may cause some behaviors that are not immediately obvious.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions