Search in sources :

Example 1 with GafferWrappedErrorRuntimeException

use of uk.gov.gchq.gaffer.core.exception.GafferWrappedErrorRuntimeException in project Gaffer by gchq.

the class ProxyStore method handleResponse.

protected <O> O handleResponse(final Response response, final ResponseDeserialiser<O> responseDeserialiser) throws StoreException {
    final String outputJson = response.hasEntity() ? response.readEntity(String.class) : null;
    if (Family.SUCCESSFUL != response.getStatusInfo().getFamily()) {
        final Error error;
        try {
            error = JSONSerialiser.deserialise(StringUtil.toBytes(outputJson), Error.class);
        } catch (final Exception e) {
            LOGGER.warn("Gaffer bad status {}. Detail: {}", response.getStatus(), outputJson);
            throw new StoreException("Delegate Gaffer store returned status: " + response.getStatus() + ". Response content was: " + outputJson);
        }
        throw new GafferWrappedErrorRuntimeException(error);
    }
    O output = null;
    if (null != outputJson) {
        try {
            output = responseDeserialiser.deserialise(outputJson);
        } catch (final SerialisationException e) {
            throw new StoreException(e.getMessage(), e);
        }
    }
    return output;
}
Also used : SerialisationException(uk.gov.gchq.gaffer.exception.SerialisationException) Error(uk.gov.gchq.gaffer.core.exception.Error) GafferWrappedErrorRuntimeException(uk.gov.gchq.gaffer.core.exception.GafferWrappedErrorRuntimeException) GafferWrappedErrorRuntimeException(uk.gov.gchq.gaffer.core.exception.GafferWrappedErrorRuntimeException) SerialisationException(uk.gov.gchq.gaffer.exception.SerialisationException) OperationException(uk.gov.gchq.gaffer.operation.OperationException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) StoreException(uk.gov.gchq.gaffer.store.StoreException) GafferRuntimeException(uk.gov.gchq.gaffer.core.exception.GafferRuntimeException) StoreException(uk.gov.gchq.gaffer.store.StoreException) OperationChainDAO(uk.gov.gchq.gaffer.operation.OperationChainDAO)

Example 2 with GafferWrappedErrorRuntimeException

use of uk.gov.gchq.gaffer.core.exception.GafferWrappedErrorRuntimeException in project Gaffer by gchq.

the class ProxyStoreBasicIT method shouldCatchAndThrowUsefulErrorMessages.

@Test
public void shouldCatchAndThrowUsefulErrorMessages() throws Exception {
    // Given
    addDefaultElements();
    // When / Then
    try {
        graph.execute(new OperationChain.Builder().first(new GetAllElements()).then(new Limit<>(1, false)).then(new ToList<>()).build(), USER);
        fail("Exception expected");
    } catch (final GafferWrappedErrorRuntimeException e) {
        assertThat(e.getError()).isEqualTo(new Error.ErrorBuilder().simpleMessage("Limit of 1 exceeded.").status(Status.INTERNAL_SERVER_ERROR).build());
    }
}
Also used : OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) Error(uk.gov.gchq.gaffer.core.exception.Error) Limit(uk.gov.gchq.gaffer.operation.impl.Limit) GafferWrappedErrorRuntimeException(uk.gov.gchq.gaffer.core.exception.GafferWrappedErrorRuntimeException) Test(org.junit.jupiter.api.Test)

Aggregations

Error (uk.gov.gchq.gaffer.core.exception.Error)2 GafferWrappedErrorRuntimeException (uk.gov.gchq.gaffer.core.exception.GafferWrappedErrorRuntimeException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Test (org.junit.jupiter.api.Test)1 GafferRuntimeException (uk.gov.gchq.gaffer.core.exception.GafferRuntimeException)1 SerialisationException (uk.gov.gchq.gaffer.exception.SerialisationException)1 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)1 OperationChainDAO (uk.gov.gchq.gaffer.operation.OperationChainDAO)1 OperationException (uk.gov.gchq.gaffer.operation.OperationException)1 Limit (uk.gov.gchq.gaffer.operation.impl.Limit)1 GetAllElements (uk.gov.gchq.gaffer.operation.impl.get.GetAllElements)1 StoreException (uk.gov.gchq.gaffer.store.StoreException)1