Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(DataPlanePublicAPI): Error message handling #4678

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ public DataPlanePublicApiV2Controller(PipelineService pipelineService,
this.executorService = executorService;
}

private static Response error(Response.Status status, String error) {
return status(status).type(APPLICATION_JSON).entity(new TransferErrorResponse(List.of(error))).build();
private static Response error(Response.Status status, List<String> errors) {
return status(status).type(APPLICATION_JSON).entity(new TransferErrorResponse(errors)).build();
}

@GET
Expand Down Expand Up @@ -135,13 +135,13 @@ private void handle(ContainerRequestContext requestContext, AsyncResponse respon

var token = contextApi.headers().get(HttpHeaders.AUTHORIZATION);
if (token == null) {
response.resume(error(UNAUTHORIZED, "Missing Authorization Header"));
response.resume(error(UNAUTHORIZED, List.of("Missing Authorization Header")));
return;
}

var sourceDataAddress = authorizationService.authorize(token, buildRequestData(requestContext));
if (sourceDataAddress.failed()) {
response.resume(error(FORBIDDEN, sourceDataAddress.getFailureDetail()));
response.resume(error(FORBIDDEN, sourceDataAddress.getFailureMessages()));
return;
}

Expand Down Expand Up @@ -173,11 +173,11 @@ private void processRequest(DataFlowStartMessage dataFlowStartMessage, AsyncResp
.whenComplete((result, throwable) -> {
if (throwable == null) {
if (result.failed()) {
response.resume(error(INTERNAL_SERVER_ERROR, result.getFailureDetail()));
response.resume(error(INTERNAL_SERVER_ERROR, result.getFailureMessages()));
}
} else {
var error = "Unhandled exception occurred during data transfer: " + throwable.getMessage();
response.resume(error(INTERNAL_SERVER_ERROR, error));
response.resume(error(INTERNAL_SERVER_ERROR, List.of(error)));
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executors;
Expand All @@ -45,7 +46,6 @@
import static java.util.concurrent.CompletableFuture.completedFuture;
import static java.util.concurrent.CompletableFuture.failedFuture;
import static org.assertj.core.api.Assertions.assertThat;
import static org.eclipse.edc.connector.dataplane.spi.pipeline.StreamFailure.Reason.GENERAL_ERROR;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.mockito.ArgumentMatchers.any;
Expand Down Expand Up @@ -117,7 +117,24 @@ void should_returnInternalServerError_if_transferFails() {
.then()
.statusCode(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode())
.contentType(JSON)
.body("errors[0]", is(GENERAL_ERROR + ": " + errorMsg));
.body("errors[0]", is(errorMsg));
}
@Test
void should_returnListOfErrorsAsAResponse_if_anythingFails() {
var token = UUID.randomUUID().toString();
var errorMsg = UUID.randomUUID().toString();
when(dataAddressResolver.resolve(any())).thenReturn(Result.success(testDestAddress()));
when(pipelineService.transfer(any(), any()))
.thenReturn(completedFuture(StreamResult.error(errorMsg)));

baseRequest()
.header(AUTHORIZATION, token)
.when()
.post("/any")
.then()
.statusCode(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode())
.contentType(JSON)
.body("errors", is(List.class));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test does not properly verify the change. Compare it to how the original test verifies the error messages.

}

@Test
Expand Down