squeaky-pl / japronto

Screaming-fast Python 3.5+ HTTP toolkit integrated with pipelining HTTP server based on uvloop and picohttpparser.
MIT License
8.61k stars 581 forks source link

How to heandle 404 error ? #125

Open vadim-shadrin opened 6 years ago

vadim-shadrin commented 6 years ago

I temporary replace string 76 in /japronto/app/init.py

vadim-shadrin commented 6 years ago

That's the right solution You need to override the method

from japronto.router import RouteNotFoundException import asyncio import traceback import sys

class App(Application): def default_error_handler(self, request, exception): if isinstance(exception, RouteNotFoundException):

return request.Response(code=404, text='Not Found'

         return request.Response(code=302,headers={'Location':'notfound'})
    if isinstance(exception, asyncio.CancelledError):
        return request.Response(code=503, text='Service unavailable')
    tb = traceback.format_exception(
        None, exception, exception.__traceback__)
    tb = ''.join(tb)
    print(tb, file=sys.stderr, end='')
    return request.Response(
        code=500,
        text=tb if self._debug else 'Internal Server Error')