Handle server errors better

This commit is contained in:
Grahame Grieve 2024-01-19 10:38:31 +11:00
parent 2156a44395
commit 29dbcbfb63
3 changed files with 17 additions and 5 deletions

View File

@ -76,15 +76,19 @@ public class ResourceUtilities {
return new XhtmlComposer(XhtmlComposer.XML).composePlainText(error.getText().getDiv());
StringBuilder b = new StringBuilder();
for (OperationOutcomeIssueComponent t : error.getIssue())
boolean first = true;
for (OperationOutcomeIssueComponent t : error.getIssue()) {
if (first) first = false; else b.append("\r\n");
String txt = t.hasDiagnostics() ? t.getDiagnostics() : gen(t.getDetails());
if (t.getSeverity() == IssueSeverity.ERROR)
b.append("Error:" + gen(t.getDetails()) + "\r\n");
b.append("Error:" + txt);
else if (t.getSeverity() == IssueSeverity.FATAL)
b.append("Fatal:" + gen(t.getDetails()) + "\r\n");
b.append("Fatal:" + txt);
else if (t.getSeverity() == IssueSeverity.WARNING)
b.append("Warning:" + gen(t.getDetails()) + "\r\n");
b.append("Warning:" + txt);
else if (t.getSeverity() == IssueSeverity.INFORMATION)
b.append("Information:" + gen(t.getDetails()) + "\r\n");
b.append("Information:" + txt);
}
return b.toString();
}

View File

@ -279,6 +279,13 @@ public class FhirRequestBuilder {
if (error != null) {
String s = ResourceUtilities.getErrorDescription(error);
String reqid = response.header("x-request-id");
if (reqid == null) {
reqid = response.header("X-Request-Id");
}
if (reqid != null) {
s = s + " ["+reqid+"]";
}
System.out.println("Error from "+source+": " + s);
throw new EFhirClientException("Error from "+source+": " + ResourceUtilities.getErrorDescription(error), error);
}