kernelsauce / turbo

Turbo is a framework built for LuaJIT 2 to simplify the task of building fast and scalable network applications. It uses a event-driven, non-blocking, no thread design to deliver excellent performance and minimal footprint to high-load applications while also providing excellent support for embedded uses.
http://turbo.readthedocs.io/
Apache License 2.0
528 stars 84 forks source link

Ways to override error pages #227

Closed rjpcomputing closed 9 years ago

rjpcomputing commented 9 years ago

Hi,

I could not find a way to override the default behavior of the error 404, 400, 500 errors. I would like to automatically send a JSON "error" structure that has been defined in other apps I have written. Can these default errors be overwritten?

Thanks.

kernelsauce commented 9 years ago

Hello.

The only way to do this at the moment is to reimplement the ErrorHandler.

turbo.web.ErrorHandler = class("ErrorHandler", web.RequestHandler)

function turbo.web.ErrorHandler:initialize(app, request, code, message)
    turbo.web.RequestHandler.initialize(self, app, request)
    if (message) then
        self:write(message)
    end
    self:set_status(code)
    self:finish()
end

Change this to whatever you want. This will be global towards all of your Applications and RequestHandlers though, so you have to run in separate processes if you want different behaviours.