Is there a way to tell the ErpNext REST API to return a JSON response when an error occurs?
I’ve been scrolling back and forth through reams of HTML to find error messages and it just occurred to me – “This isn’t even remotely normal! Since when does a computer to computer interface return a computer to human response to report an error?”
It’s an inconsistent design. That said, fixing it would require changing your app.py file or changing the way that errors are handled in the front end of frappe.
frappe.flags.read_only = True
# If replica is available then just connect replica, else setup read only transaction.
def log_request(request, response):
if hasattr(frappe.local, "conf") and frappe.local.conf.enable_frappe_logger:
"remote_addr": getattr(request, "remote_addr", "NOTFOUND"),
"base_url": getattr(request, "base_url", "NOTFOUND"),
"full_path": getattr(request, "full_path", "NOTFOUND"),
"method": getattr(request, "method", "NOTFOUND"),
"scheme": getattr(request, "scheme", "NOTFOUND"),
"http_status_code": getattr(response, "status_code", "NOTFOUND"),
That flag is set to
False and is not available outside that function. It’s set another half dozen times below there as well.
So it’s a candidate for a feature request in GitHub?
Sorta what I thought, but …
… am I really the first to ask about this?
It’s quite an egregious breach of the REST “contract”, don’t you think?
This is just a workaround, it doesn’t solve the issue. If the api consumer app can handle the response something like following can be done:
if EMPLOYEE_NOT_FOUND_ERROR_MESSAGE in error_str
Not so easy to solve, as you can read