How to return specific HTTP code and body via RPC API

How to return specific HTTP code and body via RPC API?
If I raise an exception, client will get HTTP 500 with a HTML error page.
I want to return HTTP 400 with some json data, how to do it?

use

frappe.local.response['http_status_code'] = 200
3 Likes

Thanks, and where I can find these definitions or more examples?

Hi @nnylyj,

for list of html status code : List of HTTP status codes - Wikipedia
example of status code in frappe : frappe/exceptions.py at develop · frappe/frappe · GitHub

Thanks,
Makarand

Continuing the discussion from How to return specific HTTP code and body via RPC API:

Ok… I mean how can I know to code such as

frappe.local.response['http_status_code'] = 200

any docs?

@nnylyj ERPNext uses the Werkzeug response object, so you can check werkzeug docs. http://werkzeug.pocoo.org/

Thanks, I will check that.