japronto icon indicating copy to clipboard operation
japronto copied to clipboard

How to heandle 404 error ?

Open vadim-shadrin opened this issue 6 years ago • 1 comments

I temporary replace string 76 in /japronto/app/init.py - return request.Response(code=404, text='Not Found') + return request.Response(code=302,headers={'Location':'notfound'}) and addroute: /notfound and it's work but . I whould not want to change global package

vadim-shadrin avatar May 13 '18 08:05 vadim-shadrin

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')

vadim-shadrin avatar Jul 08 '18 15:07 vadim-shadrin