How to stop displaying stacktrace and http error reports generated by openmrs and display instead custom error response

Hi,

Whenever we try to hit any custom module invalid endpoint , or whenever any internal error occurs in those cases OpenMRS returns complete stacktrace of error in form json body or an http error report page such as 500 error html page or 403 forbidden error html page. We want to stop showing those pages and instead want to handle with help of custom error json body, and return it finally to the api client.

How to proceed on this, we also weren’t able to find any stop printing stack trace property which we can use.

We tried implementing a error filter in our module so it was able to handle the 500 json based error but in some cases we found openMRS was overriding it returning a 500 html error report page and also the 403 forbidden error which our filter wasn’t able to override.

Any solution on openMRS core level such that we only receive a custom error json response to our client after trapping the actual json/html error body.

Urgent help required. @dkayiwa

OpenMRS team, any update on this?

@helpdesk1 @dkayiwa Can you please help with this.

Kindly share the entire error logs using pastebin.

Is there a way to suppress the stacktrace as part of REST call response? This is also a security issue wrt to revealing accidental information. I was looking if there is any configuration but haven’t found anything. My first impression is that it should be possible to handle in the exception handlers defined in “BaseRestController”, we can just introduce a property whether to pack the stacktrace inside response or not. (assuming its done by RestUtil.wrapErrorResponse). Thoughts?

@dkayiwa @ibacher @burke

I am not aware of any such configuration. Introducing a property that RestUtil.wrapErrorResponse checks to determine whether to include the stack trace or not, makes sense to me.

Hi @dkayiwa I have raised the below PR by having a global property check to determine whether to show stack trace details or not.

@deepthi do you mind creating a JIRA ticket for it? Tickets - Documentation - OpenMRS Wiki

@dkayiwa sure have created the ticket below is the link https://issues.openmrs.org/browse/RESTWS-921