Search in sources :

Example 11 with ErrorMessage

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();
    }
}
Also used : Response(com.yahoo.jdisc.Response) Chain(com.yahoo.component.chain.Chain) Processor(com.yahoo.processing.Processor) ErrorMessage(com.yahoo.processing.request.ErrorMessage) Test(org.junit.Test)

Example 12 with ErrorMessage

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;
}
Also used : ErrorMessage(com.yahoo.processing.request.ErrorMessage)

Example 13 with ErrorMessage

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;
}
Also used : ErrorMessage(com.yahoo.processing.request.ErrorMessage)

Example 14 with ErrorMessage

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++;
}
Also used : IdentityHashMap(java.util.IdentityHashMap) ErrorMessage(com.yahoo.processing.request.ErrorMessage)

Example 15 with ErrorMessage

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;
}
Also used : Iterator(java.util.Iterator) ErrorMessage(com.yahoo.processing.request.ErrorMessage) XMLWriter(com.yahoo.text.XMLWriter)

Aggregations

ErrorMessage (com.yahoo.processing.request.ErrorMessage)19 Test (org.junit.Test)13 Chain (com.yahoo.component.chain.Chain)3 Processor (com.yahoo.processing.Processor)3 Request (com.yahoo.processing.Request)2 Query (com.yahoo.search.Query)2 Result (com.yahoo.search.Result)2 XMLWriter (com.yahoo.text.XMLWriter)2 Iterator (java.util.Iterator)2 Response (com.yahoo.jdisc.Response)1 AsynchronousSectionedRenderer (com.yahoo.processing.rendering.AsynchronousSectionedRenderer)1 ProcessingRenderer (com.yahoo.processing.rendering.ProcessingRenderer)1 Renderer (com.yahoo.processing.rendering.Renderer)1 IOException (java.io.IOException)1 IdentityHashMap (java.util.IdentityHashMap)1