Sunday, 15 August 2010

json - Is there a a way to change the default content-type to all Bottle's error responses at once? -


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