Skip to content

Commit

Permalink
[ALS-0000] - 500 for 401 on sites
Browse files Browse the repository at this point in the history
  • Loading branch information
Luke Sikina committed Oct 23, 2023
1 parent f2dc837 commit 97c29f6
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,8 @@ public HttpResponse retrievePostResponse(String uri, Header[] headers, String bo
public void throwResponseError(HttpResponse response, String baseURL) {
edu.harvard.dbmi.avillach.util.HttpClientUtil.throwResponseError(response, baseURL);
}

public void throwInternalResponseError(HttpResponse response, String baseURL) {
edu.harvard.dbmi.avillach.util.HttpClientUtil.throwInternalResponseError(response, baseURL);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public ResourceInfo info(QueryRequest infoRequest) {
if (response.getStatusLine().getStatusCode() != 200) {
logger.error("{}{} did not return a 200: {} {} ", properties.getTargetPicsureUrl(), pathName,
response.getStatusLine().getStatusCode(), response.getStatusLine().getReasonPhrase());
httpClient.throwResponseError(response, properties.getTargetPicsureUrl());
httpClient.throwInternalResponseError(response, properties.getTargetPicsureUrl());
}

ResourceInfo resourceInfo = httpClient.readObjectFromResponse(response, ResourceInfo.class);
Expand Down Expand Up @@ -110,7 +110,7 @@ public QueryStatus query(QueryRequest queryRequest) {
logger.error("{}{} calling resource with id {} did not return a 200: {} {} ",
properties.getTargetPicsureUrl(), pathName, chainRequest.getResourceUUID(),
response.getStatusLine().getStatusCode(), response.getStatusLine().getReasonPhrase());
httpClient.throwResponseError(response, properties.getTargetPicsureUrl());
httpClient.throwInternalResponseError(response, properties.getTargetPicsureUrl());
}
QueryStatus queryStatus = httpClient.readObjectFromResponse(response, QueryStatus.class);
queryStatus.setResourceID(queryRequest.getResourceUUID());
Expand Down Expand Up @@ -146,7 +146,7 @@ public Response queryResult(@PathParam("resourceQueryId") String queryId, QueryR
logger.error("{}{} calling resource with id {} did not return a 200: {} {} ",
properties.getTargetPicsureUrl(), pathName, chainRequest.getResourceUUID(),
response.getStatusLine().getStatusCode(), response.getStatusLine().getReasonPhrase());
httpClient.throwResponseError(response, properties.getTargetPicsureUrl());
httpClient.throwInternalResponseError(response, properties.getTargetPicsureUrl());
}

return Response.ok(response.getEntity().getContent()).build();
Expand Down Expand Up @@ -182,7 +182,7 @@ public QueryStatus queryStatus(@PathParam("resourceQueryId") String queryId, Que
logger.error("{}{} calling resource with id {} did not return a 200: {} {} ",
properties.getTargetPicsureUrl(), pathName, chainRequest.getResourceUUID(),
response.getStatusLine().getStatusCode(), response.getStatusLine().getReasonPhrase());
httpClient.throwResponseError(response, properties.getTargetPicsureUrl());
httpClient.throwInternalResponseError(response, properties.getTargetPicsureUrl());
}
QueryStatus queryStatus = httpClient.readObjectFromResponse(response, QueryStatus.class);
queryStatus.setResourceID(statusRequest.getResourceUUID());
Expand Down Expand Up @@ -223,7 +223,7 @@ public Response querySync(QueryRequest queryRequest) {
logger.error("{}{} calling resource with id {} did not return a 200: {} {} ",
properties.getTargetPicsureUrl(), pathName, chainRequest.getResourceUUID(),
response.getStatusLine().getStatusCode(), response.getStatusLine().getReasonPhrase());
httpClient.throwResponseError(response, properties.getTargetPicsureUrl());
httpClient.throwInternalResponseError(response, properties.getTargetPicsureUrl());
}

if (response.containsHeader(QUERY_METADATA_FIELD)) {
Expand Down Expand Up @@ -267,7 +267,7 @@ public SearchResults search(QueryRequest searchRequest) {
if (response.getStatusLine().getStatusCode() != 200) {
logger.error("{}{} did not return a 200: {} {} ", properties.getTargetPicsureUrl(), pathName,
response.getStatusLine().getStatusCode(), response.getStatusLine().getReasonPhrase());
httpClient.throwResponseError(response, properties.getTargetPicsureUrl());
httpClient.throwInternalResponseError(response, properties.getTargetPicsureUrl());
}
return httpClient.readObjectFromResponse(response, SearchResults.class);
} catch (IOException e) {
Expand Down Expand Up @@ -303,7 +303,7 @@ public Response queryFormat(QueryRequest queryRequest) {
logger.error("{}{} calling resource with id {} did not return a 200: {} {} ",
properties.getTargetPicsureUrl(), pathName, chainRequest.getResourceUUID(),
response.getStatusLine().getStatusCode(), response.getStatusLine().getReasonPhrase());
httpClient.throwResponseError(response, properties.getTargetPicsureUrl());
httpClient.throwInternalResponseError(response, properties.getTargetPicsureUrl());
}

return Response.ok(response.getEntity().getContent()).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,22 @@ public static void throwResponseError(HttpResponse response, String baseURL) {
throw new ResourceInterfaceException(errorMessage);
}

public static void throwInternalResponseError(HttpResponse response, String baseURL) {
// We don't want to propagate 401s. A site 401ing is a server side error and should
// 500 in the common area.
String errorMessage = baseURL + " " + response.getStatusLine().getStatusCode() + " "
+ response.getStatusLine().getReasonPhrase();
try {
JsonNode responseNode = json.readTree(response.getEntity().getContent());
if (responseNode != null && responseNode.has("message")) {
errorMessage += "/n" + responseNode.get("message").asText();
}
} catch (IOException e) {
// That's fine, there's no message
}
throw new ResourceInterfaceException(errorMessage);
}

/**
* Basic and general post function using Apache Http Client
*
Expand Down

0 comments on commit 97c29f6

Please sign in to comment.