use of com.yahoo.processing.request.ErrorMessage in project vespa by vespa-engine.
the class ProcessingHandlerTestCase method testResponseDataStatusOverridesErrors.
/**
* Tests that the ResponseStatus takes precedence over errors
*/
@Test
public void testResponseDataStatusOverridesErrors() throws InterruptedException {
ProcessingTestDriver.MockResponseHandler responseHandler = null;
try {
List<Chain<Processor>> chains = new ArrayList<>();
chains.add(new Chain<Processor>("default", new ResponseStatusSetter(200), new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.FORBIDDEN.code, "Message"))));
driver = new ProcessingTestDriver(chains);
responseHandler = driver.sendRequest("http://localhost/?chain=default").awaitResponse();
Response response = responseHandler.getResponse();
assertEquals(200, response.getStatus());
} finally {
if (responseHandler != null)
responseHandler.readAll();
}
}
use of com.yahoo.processing.request.ErrorMessage in project vespa by vespa-engine.
the class VespaHeaders method webServiceCodes.
private static Tuple2<Boolean, Integer> webServiceCodes(ErrorMessage mainError, Iterator<? extends ErrorMessage> allErrors) {
if (mainError == null)
return NO_MATCH;
Iterator<? extends ErrorMessage> errorIterator = allErrors;
if (errorIterator != null && errorIterator.hasNext()) {
for (; errorIterator.hasNext(); ) {
ErrorMessage error = errorIterator.next();
Tuple2<Boolean, Integer> status = chooseWebServiceStatus(error);
if (status.first) {
return status;
}
}
} else {
Tuple2<Boolean, Integer> status = chooseWebServiceStatus(mainError);
if (status.first) {
return status;
}
}
return NO_MATCH;
}
use of com.yahoo.processing.request.ErrorMessage in project vespa by vespa-engine.
the class VespaHeaders method getEagerErrorStatus.
/**
* Returns 5xx or 4xx if there is any error present in the result, 200 otherwise
*
* @param mainError The main error of the response.
* @param allErrors All the errors of the response, if any.
* @return The error status code of the given response.
*/
public static int getEagerErrorStatus(ErrorMessage mainError, Iterator<? extends ErrorMessage> allErrors) {
if (mainError == null)
return Response.Status.OK;
// Iterate over all errors
if (allErrors != null && allErrors.hasNext()) {
for (; allErrors.hasNext(); ) {
ErrorMessage error = allErrors.next();
Tuple2<Boolean, Integer> status = chooseStatusFromError(error);
if (status.first) {
return status.second;
}
}
} else {
Tuple2<Boolean, Integer> status = chooseStatusFromError(mainError);
if (status.first) {
return status.second;
}
}
// Default return code for errors
return Response.Status.INTERNAL_SERVER_ERROR;
}
use of com.yahoo.processing.request.ErrorMessage in project vespa by vespa-engine.
the class ProcessingRenderer method beginList.
@Override
public final void beginList(DataList<?> list) throws IOException {
if (level > 0)
jsonWriter.beginArrayValue();
jsonWriter.beginObject();
if (level == 0)
renderTrace();
if (!list.request().errors().isEmpty() && !rendered(list.request())) {
jsonWriter.beginField("errors");
jsonWriter.beginArray();
for (ErrorMessage error : list.request().errors()) {
if (renderedRequests == null)
renderedRequests = new IdentityHashMap<>();
renderedRequests.put(list.request(), list.request());
jsonWriter.beginArrayValue();
if (error.getCause() != null) {
// render object
jsonWriter.beginObject();
jsonWriter.beginField("error").value(error.toString()).endField();
jsonWriter.beginField("stacktrace").value(stackTraceAsString(error.getCause())).endField();
jsonWriter.endObject();
} else {
// render string
jsonWriter.value(error.toString());
}
jsonWriter.endArrayValue();
}
jsonWriter.endArray();
jsonWriter.endField();
}
jsonWriter.beginField("datalist");
jsonWriter.beginArray();
level++;
}
use of com.yahoo.processing.request.ErrorMessage in project vespa by vespa-engine.
the class SearchRendererAdaptor method simpleRenderDefaultErrorHit.
public static boolean simpleRenderDefaultErrorHit(Writer writer, ErrorHit defaultErrorHit) throws IOException {
XMLWriter xmlWriter = (writer instanceof XMLWriter) ? (XMLWriter) writer : new XMLWriter(writer, 10, -1);
xmlWriter.openTag("errordetails");
for (Iterator i = defaultErrorHit.errorIterator(); i.hasNext(); ) {
ErrorMessage error = (ErrorMessage) i.next();
renderMessageDefaultErrorHit(xmlWriter, error);
}
xmlWriter.closeTag();
return true;
}
Aggregations