Skip to content

Commit

Permalink
chore(DataPlanePublicAPI): Error message handling
Browse files Browse the repository at this point in the history
Changed error handling method to be returned directly as list, instead of being concatenated first and then wrapped to the list
  • Loading branch information
kkotowiczz committed Dec 16, 2024
1 parent dd54469 commit 053f6b2
Showing 1 changed file with 6 additions and 6 deletions.
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

0 comments on commit 053f6b2

Please sign in to comment.