Skip to content

Commit

Permalink
MAT-7233: Pass back the error components so that the message can be a…
Browse files Browse the repository at this point in the history
…ssembled and formatted by the frontend.
  • Loading branch information
jkotanchik-SB committed Jun 14, 2024
1 parent 282aa22 commit 74bcb2f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,26 +67,28 @@ Map<String, Object> onMissingServletRequestParameterException(

@ExceptionHandler(VsacValueSetExpansionException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
ResponseEntity<Map<String, Object>> onVsacValueSetExpansionException(
@ResponseBody
Map<String, Object> onVsacValueSetExpansionException(
VsacValueSetExpansionException ex, WebRequest request) {
IParser parser = fhirContext.newJsonParser();
OperationOutcome outcome = parser.parseResource(OperationOutcome.class, ex.getBody());
String filter = ex.getFilter();
if (filter.contains("Manifest")) {
filter += " " + ex.getValueSetUrl().substring(ex.getValueSetUrl().lastIndexOf("Library/"));

Map<String, Object> errorAttributes =
getErrorAttributes(request, HttpStatus.valueOf(ex.getStatusCode().value()));

errorAttributes.put("diagnostic", outcome.getIssueFirstRep().getDiagnostics());
errorAttributes.put(
"valueSet",
ex.getValueSetUri()
.substring("ValueSet/".length() + 1, ex.getValueSetUri().lastIndexOf("/$")));
if (ex.getFilter().equalsIgnoreCase("manifest") && ex.getValueSetUri().contains("Library/")) {
errorAttributes.put(
"manifest",
ex.getValueSetUri()
.substring(ex.getValueSetUri().lastIndexOf("Library/") + "Library/".length()));
}
String message =
String.format(
"Value Set %s could not be expanded using %s. Per VSAC, \"%s\"\n\n (DEBUG) URL: %s",
ex.getValueSetUrl()
.substring("ValueSet/".length() + 1, ex.getValueSetUrl().lastIndexOf("/$")),
filter,
outcome.getIssueFirstRep().getDiagnostics(),
ex.getValueSetUrl());
return handleWebClientResponseException(
new WebClientResponseException(
message, ex.getStatusCode(), ex.getStatusText(), null, null, null, null),
request);

return errorAttributes;
}

@ExceptionHandler(VsacGenericException.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ public class VsacValueSetExpansionException extends WebClientResponseException {

private String body;
private String filter;
private String valueSetUrl;
private String valueSetUri;

public VsacValueSetExpansionException(
String message,
HttpStatusCode status,
String statusText,
String body,
String filter,
String valueSetUrl) {
String valueSetUri) {
super(message, status, statusText, null, body.getBytes(), Charset.defaultCharset(), null);
this.body = body;
this.filter = filter;
this.valueSetUrl = valueSetUrl;
this.valueSetUri = valueSetUri;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package gov.cms.madie.terminology.controller;

import ca.uhn.fhir.context.FhirContext;
import gov.cms.madie.models.measure.ManifestExpansion;
import gov.cms.madie.terminology.dto.Code;
import gov.cms.madie.terminology.dto.QdmValueSet;
Expand Down Expand Up @@ -42,6 +43,8 @@ class VsacFhirTerminologyControllerMvcTest {

@MockBean private FhirTerminologyService fhirTerminologyService;

@MockBean private FhirContext fhirContext;

@Autowired private MockMvc mockMvc;

private UmlsUser umlsUser;
Expand Down

0 comments on commit 74bcb2f

Please sign in to comment.