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 : https://en.wikipedia.org/wiki/List_of_HTTP_status_codes
example of status code in frappe : https://github.com/frappe/frappe/blob/develop/frappe/exceptions.py

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.