Skip to content
Permalink
Browse files
BATCHEE-45 improve error handling for simpleRest
  • Loading branch information
struberg committed Jul 12, 2014
1 parent 1ec5670 commit 08d7623f89b7b66da4515ec1baa63a37b69a7ad8
Showing 1 changed file with 15 additions and 6 deletions.
@@ -88,14 +88,11 @@ private void startBatch(String batchName, HttpServletRequest req, HttpServletRes
} catch (JobStartException jobStartException) {
StringBuilder msg = new StringBuilder("Error while starting job ");
msg.append(batchName).append('\n');
msg.append(jobStartException.getMessage()).append('\n');
StringWriter sw = new StringWriter();
jobStartException.printStackTrace(new PrintWriter(sw));
msg.append(sw.toString());

appendExceptionMsg(msg, jobStartException);
reportFailure(NO_JOB_ID, resp, msg.toString());
}
}

private void batchStatus(String batchId, HttpServletRequest req, HttpServletResponse resp)
{
if (batchId == null || batchId.isEmpty()) {
@@ -117,6 +114,10 @@ private void batchStatus(String batchId, HttpServletRequest req, HttpServletResp
reportSuccess(executionId, resp, batchStatus.name());
} catch (NoSuchJobExecutionException noSuchJob) {
reportFailure(executionId, resp, "NoSuchJob");
} catch (Exception generalException) {
StringBuilder msg = new StringBuilder("NoSuchJob");
appendExceptionMsg(msg, generalException);
reportFailure(executionId, resp, msg.toString());
}
}

@@ -134,7 +135,7 @@ private void unknownCommand(String path, HttpServletResponse resp) {
msg.append(" will return the state of executionId 23\n\n");

msg.append("The returned response if of MIME type text/plain and contains the following information\n");
msg.append(" {jobId}\\n\n");
msg.append(" {jobExecutionId} (or -1 if no executionId was detected)\\n\n");
msg.append(" OK (or FAILURE)\\n\n");
msg.append(" followed by command specific information\n");

@@ -164,4 +165,12 @@ private void writeContent(HttpServletResponse resp, String content) {
throw new RuntimeException(ioe);
}
}

private void appendExceptionMsg(StringBuilder msg, Exception exception) {
msg.append(exception.getMessage()).append('\n');
StringWriter sw = new StringWriter();
exception.printStackTrace(new PrintWriter(sw));
msg.append(sw.toString());
}

}

0 comments on commit 08d7623

Please sign in to comment.