Skip to content

generateView at 'onRequest' extension point #1137

Description

@joliss

I'm trying to use request.generateView to generate a custom error page in an 'onRequest' extension function, like so:

server.ext('onRequest', function (request, next) {
  if (errorCondition)
    next(request.generateView('error', {message: 'Foo'}))
  else
    next()
})

request.generateView fails in request.js:716 with

Debug: hapi, uncaught, onRequest, error TypeError: Cannot read property 'env' of null
    at internals.Request.generateView (.../node_modules/hapi/lib/request.js:716:35)

Changing request.js:716 to

    var viewsManager = (this._route && this._route.env.views) || this.server._views;

in order to guard against missing this._route seems to fix it, but I don't know if that's the correct fix. I'm not sure if calling request.generateView at that point is supposed to be supported at all.

Activity

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

Metadata

Metadata

Assignees

Labels

bugBug or defect

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions