Bharat Pahalwani
Bharat Pahalwani

Reputation: 1698

Disable error stack trace in dropwizard health check

Whenever my health checks are failed it is showing response as :

  "Health check Name": {
    "healthy": false,
    "error": {
      "message": null,
      "stack": [
            Stack Trace Message
      ]
    }
  },

I just want to show a simple error message instead of Stack Trace of it. And store that exception in log or display in console.

Upvotes: 1

Views: 807

Answers (2)

Bharat Pahalwani
Bharat Pahalwani

Reputation: 1698

Further adding to @[Kai Sternad]'s answer, I override the execute method of HealthCheck class in my testHeathCheck as

@Override
public Result execute() {
    try {
        return check();
    } catch (Exception e) {
        LOG.error(e);
        return Result.unhealthy("User defined error message");
    }
}

HealthCheck response for failed case :

  "Health check Name": {
    "healthy": false,
    "message": "User defined error message"
  },

Upvotes: 1

Kai Sternad
Kai Sternad

Reputation: 22830

According to the source code it doesn't look like this is configurable. Whenever an exception occurs, health check wraps it and displays it. You'll have to make your service not throw an exception or wrap it if you don't want it carried through.

Upvotes: 1

Related Questions