squeaky-pl/japronto

How to heandle 404 error ?

vadim-shadrin opened this issue · 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

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