Discussion:
[bottlepy] Returning json in error handlers.
Martin Frlin
2015-10-15 13:46:25 UTC
Permalink
I want to return simple json responses from error handlers, so my code is
somehting like this:

@app.error(401)
@app.error(404)
def error_handler(error):
return {'msg': error.body}

But this does not work as it returns nothing at all.

auto json feature does not work in error handlers?

Oh, and if anyone could explain why documentation says I need to import
error from bottle and then use it like @error(404)? error is an instance
method on Bottle class so I don't know how would it get "self" imported and
used like in documentation.
--
--
You are member of the "bottlepy" group at google groups.
See http://groups.google.de/group/bottlepy for mailing list options.
See http://bottlepy.org/ for news and documentation.

---
You received this message because you are subscribed to the Google Groups "bottlepy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bottlepy+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Daniel Watrous
2015-10-18 02:48:44 UTC
Permalink
I've noticed this too, but haven't figured out why it works this way. Here
is what i have in my code

@appv1.error(500)
def error_json_generic(error):
bottle.response.content_type = 'application/json'
return '{"error_message": "%s"}' % error.body
Post by Martin Frlin
I want to return simple json responses from error handlers, so my code is
@app.error(401)
@app.error(404)
return {'msg': error.body}
But this does not work as it returns nothing at all.
auto json feature does not work in error handlers?
Oh, and if anyone could explain why documentation says I need to import
method on Bottle class so I don't know how would it get "self" imported and
used like in documentation.
--
--
You are member of the "bottlepy" group at google groups.
See http://groups.google.de/group/bottlepy for mailing list options.
See http://bottlepy.org/ for news and documentation.

---
You received this message because you are subscribed to the Google Groups "bottlepy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bottlepy+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...