Skip to content
This repository has been archived by the owner on May 7, 2020. It is now read-only.

Commit

Permalink
improved error handling in ChartServlet (#4524)
Browse files Browse the repository at this point in the history
Signed-off-by: Kai Kreuzer <kai@openhab.org>
  • Loading branch information
kaikreuzer authored and sjsf committed Nov 9, 2017
1 parent 527c75f commit 0cbca7a
Showing 1 changed file with 11 additions and 1 deletion.
Expand Up @@ -295,12 +295,22 @@ protected void doGet(HttpServletRequest req, HttpServletResponse res) throws Ser
BufferedImage chart = provider.createChart(serviceName, req.getParameter("theme"), timeBegin, timeEnd,
height, width, req.getParameter("items"), req.getParameter("groups"), dpi, legend);
ImageIO.write(chart, provider.getChartType().toString(), imageOutputStream);
logger.debug("Chart successfully generated and written to the response.");
} catch (ItemNotFoundException e) {
logger.debug("{}", e.getMessage());
res.sendError(HttpServletResponse.SC_BAD_REQUEST, e.getMessage());
} catch (IllegalArgumentException e) {
logger.warn("Illegal argument in chart: {}", e.getMessage());
res.sendError(HttpServletResponse.SC_BAD_REQUEST, "Illegal argument in chart: " + e.getMessage());
} catch (RuntimeException e) {
if (logger.isDebugEnabled()) {
// we also attach the stack trace
logger.warn("Chart generation failed: {}", e.getMessage(), e);
} else {
logger.warn("Chart generation failed: {}", e.getMessage());
}
res.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
}
logger.debug("chart built");
}

/**
Expand Down

0 comments on commit 0cbca7a

Please sign in to comment.