Skip to content

Commit

Permalink
EDGPATRON-149 Formatting response
Browse files Browse the repository at this point in the history
  • Loading branch information
Vignesh-kalyanasundaram committed Oct 16, 2024
1 parent dddd0ee commit ec360d3
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion src/main/java/org/folio/edge/patron/PatronHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ public void handleGetPatronRegistrationStatus(RoutingContext ctx) {
String alternateTenantId = ctx.request().getParam("alternateTenantId", client.tenant);
final PatronOkapiClient patronClient = new PatronOkapiClient(client, alternateTenantId);
patronClient.getExtPatronAccountByEmail(params.get(PARAM_EMAIL_ID),
resp -> handleProxyResponse(ctx, resp),
resp -> handleRegistrationStatusResponse(ctx, resp),
t -> handleProxyException(ctx, t));
});
}
Expand Down Expand Up @@ -343,6 +343,32 @@ protected void handleProxyResponse(RoutingContext ctx, HttpResponse<Buffer> resp
}
}

protected void handleRegistrationStatusResponse(RoutingContext ctx, HttpResponse<Buffer> resp) {
HttpServerResponse serverResponse = ctx.response();

int statusCode = resp.statusCode();
serverResponse.setStatusCode(statusCode);

String respBody = resp.bodyAsString();
if (logger.isDebugEnabled() ) {
logger.debug("handleRegistrationStatusResponse:: response {} ", respBody);
}

String contentType = resp.getHeader(HttpHeaders.CONTENT_TYPE.toString());

if (resp.statusCode() < 400 && Objects.nonNull(respBody)){
setContentType(serverResponse, contentType);
serverResponse.end(respBody); //not an error case, pass on the response body as received
}
else {
String errorMsg = (statusCode == 404 || statusCode == 400 || statusCode == 422)
? get422ErrorMsg(statusCode, respBody)
: getStructuredErrorMessage(statusCode, respBody);
setContentType(serverResponse, APPLICATION_JSON);
serverResponse.end(errorMsg);
}
}

@Override
protected void handleProxyException(RoutingContext ctx, Throwable t) {
logger.error("Exception retrieving data from mod-patron:", t);
Expand Down

0 comments on commit ec360d3

Please sign in to comment.