Skip to content

Commit

Permalink
feat(ConsumerProxy): enhances error response when fetching data (#780)
Browse files Browse the repository at this point in the history
* feat(ConsumerProxy): enhances error response when fetching data

* chore: dependencies file
  • Loading branch information
wolf4ood authored Sep 22, 2023
1 parent c8dd495 commit ceb3cec
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
4 changes: 2 additions & 2 deletions DEPENDENCIES
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ maven/mavencentral/jakarta.annotation/jakarta.annotation-api/2.1.1, EPL-2.0 OR G
maven/mavencentral/jakarta.inject/jakarta.inject-api/2.0.1, Apache-2.0, approved, clearlydefined
maven/mavencentral/jakarta.json/jakarta.json-api/2.1.1, EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0, approved, #7907
maven/mavencentral/jakarta.transaction/jakarta.transaction-api/2.0.0, EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0, approved, #7697
maven/mavencentral/jakarta.validation/jakarta.validation-api/2.0.2, Apache-2.0, approved, clearlydefined
maven/mavencentral/jakarta.validation/jakarta.validation-api/3.0.2, Apache-2.0, approved, clearlydefined
maven/mavencentral/jakarta.validation/jakarta.validation-api/2.0.2, Apache-2.0, approved, ee4j.validation
maven/mavencentral/jakarta.validation/jakarta.validation-api/3.0.2, Apache-2.0, approved, ee4j.validation
maven/mavencentral/jakarta.ws.rs/jakarta.ws.rs-api/3.1.0, EPL-2.0 OR GPL-2.0-only with Classpath-exception-2.0, approved, ee4j.rest
maven/mavencentral/jakarta.xml.bind/jakarta.xml.bind-api/2.3.2, BSD-3-Clause, approved, ee4j.jaxb
maven/mavencentral/jakarta.xml.bind/jakarta.xml.bind-api/3.0.0, BSD-3-Clause, approved, ee4j.jaxb
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.ext.ExceptionMapper;
import jakarta.ws.rs.ext.Provider;
import org.eclipse.edc.web.spi.ApiErrorDetail;

/**
* Maps client errors to return the associated status.
Expand All @@ -30,7 +31,8 @@ public ClientErrorExceptionMapper() {

@Override
public Response toResponse(ClientErrorException exception) {
return Response.status(exception.getResponse().getStatus()).build();
var detail = ApiErrorDetail.Builder.newInstance().message(exception.getMessage()).build();
return Response.status(exception.getResponse().getStatus()).entity(detail).build();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
import jakarta.ws.rs.BadRequestException;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.container.AsyncResponse;
import jakarta.ws.rs.container.Suspended;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.StreamingOutput;
import org.eclipse.edc.connector.dataplane.spi.manager.DataPlaneManager;
import org.eclipse.edc.connector.dataplane.spi.pipeline.StreamResult;
Expand Down Expand Up @@ -51,6 +53,7 @@
* Implements the HTTP proxy API.
*/
@Path("/aas")
@Produces(MediaType.APPLICATION_JSON)
public class ConsumerAssetRequestController implements ConsumerAssetRequestApi {
public static final String BASE_URL = "baseUrl";
private static final String HTTP_DATA = "HttpData";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.eclipse.edc.spi.types.domain.edr.EndpointDataReference;
import org.eclipse.edc.spi.types.domain.transfer.DataFlowRequest;
import org.eclipse.edc.web.jersey.testfixtures.RestControllerTestBase;
import org.eclipse.tractusx.edc.dataplane.proxy.consumer.api.asset.ClientErrorExceptionMapper;
import org.eclipse.tractusx.edc.dataplane.proxy.consumer.api.asset.ConsumerAssetRequestController;
import org.eclipse.tractusx.edc.edr.spi.store.EndpointDataReferenceCache;
import org.junit.jupiter.api.Test;
Expand All @@ -53,6 +54,7 @@
import static org.eclipse.edc.connector.dataplane.spi.schema.DataFlowRequestSchema.PATH;
import static org.eclipse.edc.connector.dataplane.spi.schema.DataFlowRequestSchema.QUERY_PARAMS;
import static org.eclipse.tractusx.edc.dataplane.proxy.consumer.api.asset.ConsumerAssetRequestController.BASE_URL;
import static org.hamcrest.Matchers.notNullValue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
Expand Down Expand Up @@ -159,7 +161,8 @@ void requestAsset_shouldReturnError_whenEdrByAssetIdNotFound() {
.body(request)
.post(ASSET_REQUEST_PATH)
.then()
.statusCode(400);
.statusCode(400)
.body("message", notNullValue());

}

Expand All @@ -184,7 +187,8 @@ void requestAsset_shouldReturnError_whenMultipleEdrsByAssetIdFound() {
.body(request)
.post(ASSET_REQUEST_PATH)
.then()
.statusCode(428);
.statusCode(428)
.body("message", notNullValue());

}

Expand Down Expand Up @@ -245,7 +249,8 @@ void requestAsset_shouldReturnError_whenEdrByTransferProcessIdNotFound() {
.body(request)
.post(ASSET_REQUEST_PATH)
.then()
.statusCode(400);
.statusCode(400)
.body("message", notNullValue());

}

Expand Down Expand Up @@ -309,6 +314,11 @@ protected Object controller() {
return new ConsumerAssetRequestController(cache, dataPlaneManager, Executors.newSingleThreadExecutor(), mock(Monitor.class));
}

@Override
protected Object additionalResource() {
return new ClientErrorExceptionMapper();
}

private RequestSpecification baseRequest() {
return given()
.baseUri("http://localhost:" + port)
Expand Down

0 comments on commit ceb3cec

Please sign in to comment.