Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error transformation does not work when serving static files #1182

Closed
WillCodeCo opened this issue Nov 30, 2013 · 0 comments
Closed

Error transformation does not work when serving static files #1182

WillCodeCo opened this issue Nov 30, 2013 · 0 comments
Assignees
Labels
bug Bug or defect
Milestone

Comments

@WillCodeCo
Copy link

I want to make a 404 error pretty. Problem is that I cannot seem to hook the error properly. This code demonstrates the problem:

// Generated by CoffeeScript 1.6.3
(function() {
  var Hapi, app_root_dir, get, is_production, options, path, routes, server, server_root_dir;

  Hapi = require('hapi');

  path = require('path');

  is_production = function() {
    return process.env.NODE_ENV === 'production';
  };

  server_root_dir = path.resolve('./');

  app_root_dir = path.join(server_root_dir, 'app');

  options = {
    cors: {
      origin: ['*']
    },
    debug: is_production() ? false : {
      request: ['error', 'uncaught']
    }
  };

  server = new Hapi.Server('localhost', (is_production() ? 80 : 8080), options);

  server.ext('onPreResponse', function(request, next) {
    var response;
    response = request._response;
    if (!response.isBoom) {
      return next();
    }
    return next({
      a_pretty_json: 'well not really'
    });
  });

  get = function(path, config) {
    return {
      path: path,
      method: 'GET',
      config: config
    };
  };

  routes = [
    get('/', {
      handler: function(request) {
        return request.reply({
          hello: 'world'
        });
      }
    }), get('/{path*}', {
      handler: {
        directory: {
          path: app_root_dir,
          listing: false,
          index: true
        }
      }
    })
  ];

  server.route(routes);

  server.start();

}).call(this);
@ghost ghost assigned hueniverse Dec 7, 2013
@lock lock bot locked as resolved and limited conversation to collaborators Jan 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Bug or defect
Projects
None yet
Development

No branches or pull requests

2 participants