I am making a small REST API in the bottle.
I only react to JSON, and although I can use error decorator @error (status_code) for every HTTP status code, it outputs to JSON, I am not quite long and practical looks like.
Does anyone know better how to do this?
OK, so I think I have managed a way to do this, though I know No how memory / programmatically efficient:
import bottle. Error (http_code) def json_error (error): bottle.response.default_content_type = "application / json" returns json.dumps (dict (error = error.status_code, message = error.status_line))
< / Div>
No comments:
Post a Comment