Skip to content
Snippets Groups Projects
Commit 3f6966d1 authored by Patrick Dowler's avatar Patrick Dowler
Browse files

fixed NPE during error reporting

parent 87de2c69
No related branches found
No related tags found
No related merge requests found
......@@ -100,6 +100,8 @@ import ca.nrc.cadc.uws.server.JobRunner;
import ca.nrc.cadc.uws.server.JobUpdater;
import ca.nrc.cadc.uws.server.SyncOutput;
import ca.nrc.cadc.uws.util.JobLogInfo;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
public class ACSearchRunner implements JobRunner
......@@ -370,16 +372,7 @@ public class ACSearchRunner implements JobRunner
logInfo.setMessage(t.getMessage());
log.error("FAIL", t);
syncOut.setResponseCode(500);
syncOut.setHeader("Content-Type", "text/plain");
try
{
syncOut.getOutputStream().write(t.getMessage().getBytes());
}
catch (IOException e)
{
log.warn("Could not write response to output stream", e);
}
writeError(syncOut, 500, t);
// ErrorSummary errorSummary =
// new ErrorSummary(t.getMessage(), ErrorType.FATAL);
......@@ -396,4 +389,23 @@ public class ACSearchRunner implements JobRunner
}
}
private void writeError(SyncOutput syncOutput, int code, Throwable t)
{
try
{
syncOutput.setResponseCode(code);
syncOut.setHeader("Content-Type", "text/plain");
OutputStream ostream = syncOut.getOutputStream();
if (ostream != null)
{
OutputStreamWriter w = new OutputStreamWriter(ostream);
w.write(t.toString());
w.flush();
}
}
catch (IOException e)
{
log.warn("Could not write response to output stream", e);
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment