Open agalera opened 7 years ago
def hello(request):
return request.Response(json=['invalid', 'json'])
Is voluntary, a valid json is always a dict, here fails to make the conversion to json.
It's a wart in the API design, I need to refactor this part. What is happening here is that an error is generated in an error handler and since request.Response was already constructed and it's immutable. It fails in a weird way swallowing the real reason.
So this is really about making Response mutable.
@kianxineki The error doesnt happen because of invalid JSON. Python JSON module will happily transform a list in a JSON array. I don't impose any extra restrictions here. This happens because of missing return.
Anyway this is an error and needs to be fixed.
Finally figured out what it is all about.
from japronto import Application
app = Application()
def hello(request):
try:
return request.Response(json=object())
except TypeError:
return request.Response(code=500) # RuntimeError due to immutable Response
app.router.add_route('/', hello, method='GET')
app.run()
If an exception is generated in the response this error appears and the request is blocked