Skip to content

Commit

Permalink
Merge pull request #6 from ochedru/master
Browse files Browse the repository at this point in the history
Handle exceptions and return http 500
  • Loading branch information
Olivier Chédru committed Feb 13, 2018
2 parents 11baa47 + 3c24670 commit 9d2ddd1
Showing 1 changed file with 6 additions and 0 deletions.
Expand Up @@ -20,13 +20,16 @@
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@SuppressWarnings("serial")
class PrometheusServlet extends HttpServlet {

public static final String METRICS_REGISTRY = MetricsServlet.class.getCanonicalName() + ".registry";
public static final String METRIC_FILTER = MetricsServlet.class.getCanonicalName() + ".metricFilter";
public static final String ALLOWED_ORIGIN = MetricsServlet.class.getCanonicalName() + ".allowedOrigin";
private static final Logger LOG = LoggerFactory.getLogger(PrometheusServlet.class);

private MetricRegistry registry;

Expand Down Expand Up @@ -108,6 +111,9 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws Se
}

writer.flush();
} catch (RuntimeException ex) {
LOG.error("Unhandled exception", ex);
resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
} finally {
writer.close();
}
Expand Down

0 comments on commit 9d2ddd1

Please sign in to comment.