Improved error messages on server failure

This commit is contained in:
Grahame Grieve 2023-08-11 14:16:09 +10:00
parent 991a2defee
commit 6041660e9b
13 changed files with 86 additions and 35 deletions

View File

@ -93,6 +93,7 @@ public class FHIRToolingClient {
public void initialize(String baseServiceUrl) throws URISyntaxException {
base = baseServiceUrl;
client.setBase(base);
resourceAddress = new ResourceAddress(baseServiceUrl);
this.allowedVersions = supportableVersions();
this.maxResultSetSize = -1;

View File

@ -22,6 +22,16 @@ public class Client {
private ToolingClientLogger logger;
private int retryCount;
private long timeout = DEFAULT_TIMEOUT;
private String base;
public String getBase() {
return base;
}
public void setBase(String base) {
this.base = base;
}
public ToolingClientLogger getLogger() {
return logger;
@ -167,7 +177,7 @@ public class Client {
String message,
int retryCount,
long timeout) throws IOException {
return new FhirRequestBuilder(request)
return new FhirRequestBuilder(request, base)
.withLogger(logger)
.withResourceFormat(resourceFormat)
.withRetryCount(retryCount)
@ -183,7 +193,7 @@ public class Client {
String message,
int retryCount,
long timeout) throws IOException {
return new FhirRequestBuilder(request)
return new FhirRequestBuilder(request, base)
.withLogger(logger)
.withResourceFormat(resourceFormat)
.withRetryCount(retryCount)

View File

@ -59,9 +59,11 @@ public class FhirRequestBuilder {
* {@link ToolingClientLogger} for log output.
*/
private ToolingClientLogger logger = null;
private String source;
public FhirRequestBuilder(Request.Builder httpRequest) {
public FhirRequestBuilder(Request.Builder httpRequest, String source) {
this.httpRequest = httpRequest;
this.source = source;
}
/**
@ -265,9 +267,9 @@ public class FhirRequestBuilder {
error = (OperationOutcome) resource;
}
} catch (IOException ioe) {
throw new EFhirClientException("Error reading Http Response: " + ioe.getMessage(), ioe);
throw new EFhirClientException("Error reading Http Response from "+source+": " + ioe.getMessage(), ioe);
} catch (Exception e) {
throw new EFhirClientException("Error parsing response message: " + e.getMessage(), e);
throw new EFhirClientException("Error parsing response message from "+source+": " + e.getMessage(), e);
}
}
@ -301,12 +303,12 @@ public class FhirRequestBuilder {
}
}
} catch (IOException ioe) {
throw new EFhirClientException("Error reading Http Response", ioe);
throw new EFhirClientException("Error reading Http Response from "+source+": "+ioe.getMessage(), ioe);
} catch (Exception e) {
throw new EFhirClientException("Error parsing response message", e);
throw new EFhirClientException("Error parsing response message from "+source+":"+e.getMessage(), e);
}
if (error != null) {
throw new EFhirClientException("Error from server: " + ResourceUtilities.getErrorDescription(error), error);
throw new EFhirClientException("Error from "+source+": " + ResourceUtilities.getErrorDescription(error), error);
}
return feed;
}

View File

@ -47,7 +47,7 @@ public class FhirRequestBuilderTests {
final Request.Builder requestBuilder = new Request.Builder()
.url(DUMMY_URL);
final FhirRequestBuilder fhirRequestBuilder = Mockito.spy(new FhirRequestBuilder(requestBuilder));
final FhirRequestBuilder fhirRequestBuilder = Mockito.spy(new FhirRequestBuilder(requestBuilder, "http://local/local"));
@Mock
OkHttpClient client;

View File

@ -93,6 +93,7 @@ public class FHIRToolingClient {
public void initialize(String baseServiceUrl) throws URISyntaxException {
base = baseServiceUrl;
client.setBase(base);
resourceAddress = new ResourceAddress(baseServiceUrl);
this.maxResultSetSize = -1;
}

View File

@ -23,6 +23,16 @@ public class Client {
private FhirLoggingInterceptor fhirLoggingInterceptor;
private int retryCount;
private long timeout = DEFAULT_TIMEOUT;
private String base;
public String getBase() {
return base;
}
public void setBase(String base) {
this.base = base;
}
public ToolingClientLogger getLogger() {
return logger;
@ -131,7 +141,7 @@ public class Client {
public <T extends Resource> Bundle executeBundleRequest(Request.Builder request, String resourceFormat,
Headers headers, String message, int retryCount, long timeout) throws IOException {
return new FhirRequestBuilder(request).withLogger(fhirLoggingInterceptor).withResourceFormat(resourceFormat)
return new FhirRequestBuilder(request, base).withLogger(fhirLoggingInterceptor).withResourceFormat(resourceFormat)
.withRetryCount(retryCount).withMessage(message)
.withHeaders(headers == null ? new Headers.Builder().build() : headers)
.withTimeout(timeout, TimeUnit.MILLISECONDS).executeAsBatch();
@ -139,7 +149,7 @@ public class Client {
public <T extends Resource> ResourceRequest<T> executeFhirRequest(Request.Builder request, String resourceFormat,
Headers headers, String message, int retryCount, long timeout) throws IOException {
return new FhirRequestBuilder(request).withLogger(fhirLoggingInterceptor).withResourceFormat(resourceFormat)
return new FhirRequestBuilder(request, base).withLogger(fhirLoggingInterceptor).withResourceFormat(resourceFormat)
.withRetryCount(retryCount).withMessage(message)
.withHeaders(headers == null ? new Headers.Builder().build() : headers)
.withTimeout(timeout, TimeUnit.MILLISECONDS).execute();

View File

@ -58,9 +58,11 @@ public class FhirRequestBuilder {
* {@link FhirLoggingInterceptor} for log output.
*/
private FhirLoggingInterceptor logger = null;
private String source;
public FhirRequestBuilder(Request.Builder httpRequest) {
public FhirRequestBuilder(Request.Builder httpRequest, String source) {
this.httpRequest = httpRequest;
this.source = source;
}
/**
@ -264,9 +266,9 @@ public class FhirRequestBuilder {
error = (OperationOutcome) resource;
}
} catch (IOException ioe) {
throw new EFhirClientException("Error reading Http Response: " + ioe.getMessage(), ioe);
throw new EFhirClientException("Error reading Http Response from "+source+": " + ioe.getMessage(), ioe);
} catch (Exception e) {
throw new EFhirClientException("Error parsing response message: " + e.getMessage(), e);
throw new EFhirClientException("Error parsing response message from "+source+": " + e.getMessage(), e);
}
}
@ -296,17 +298,17 @@ public class FhirRequestBuilder {
else if (rf instanceof OperationOutcome && hasError((OperationOutcome) rf)) {
error = (OperationOutcome) rf;
} else {
throw new EFhirClientException("Error reading server response: a resource was returned instead");
throw new EFhirClientException("Error reading server response from "+source+": a resource was returned instead");
}
}
}
} catch (IOException ioe) {
throw new EFhirClientException("Error reading Http Response", ioe);
throw new EFhirClientException("Error reading Http Response from "+source+":"+ioe.getMessage(), ioe);
} catch (Exception e) {
throw new EFhirClientException("Error parsing response message", e);
throw new EFhirClientException("Error parsing response message from "+source+":"+e.getMessage(), e);
}
if (error != null) {
throw new EFhirClientException("Error from server: " + ResourceUtilities.getErrorDescription(error), error);
throw new EFhirClientException("Error from "+source+": " + ResourceUtilities.getErrorDescription(error), error);
}
return feed;
}

View File

@ -110,6 +110,7 @@ public class FHIRToolingClient {
public void initialize(String baseServiceUrl) throws URISyntaxException {
base = baseServiceUrl;
client.setBase(base);
resourceAddress = new ResourceAddress(baseServiceUrl);
this.maxResultSetSize = -1;
checkCapabilities();

View File

@ -23,6 +23,16 @@ public class Client {
private int retryCount;
private long timeout = DEFAULT_TIMEOUT;
private byte[] payload;
private String base;
public String getBase() {
return base;
}
public void setBase(String base) {
this.base = base;
}
public ToolingClientLogger getLogger() {
return logger;
@ -135,7 +145,7 @@ public class Client {
public <T extends Resource> Bundle executeBundleRequest(Request.Builder request, String resourceFormat,
Headers headers, String message, int retryCount, long timeout) throws IOException {
return new FhirRequestBuilder(request).withLogger(fhirLoggingInterceptor).withResourceFormat(resourceFormat)
return new FhirRequestBuilder(request, base).withLogger(fhirLoggingInterceptor).withResourceFormat(resourceFormat)
.withRetryCount(retryCount).withMessage(message)
.withHeaders(headers == null ? new Headers.Builder().build() : headers)
.withTimeout(timeout, TimeUnit.MILLISECONDS).executeAsBatch();
@ -143,7 +153,7 @@ public class Client {
public <T extends Resource> ResourceRequest<T> executeFhirRequest(Request.Builder request, String resourceFormat,
Headers headers, String message, int retryCount, long timeout) throws IOException {
return new FhirRequestBuilder(request).withLogger(fhirLoggingInterceptor).withResourceFormat(resourceFormat)
return new FhirRequestBuilder(request, base).withLogger(fhirLoggingInterceptor).withResourceFormat(resourceFormat)
.withRetryCount(retryCount).withMessage(message)
.withHeaders(headers == null ? new Headers.Builder().build() : headers)
.withTimeout(timeout, TimeUnit.MILLISECONDS).execute();

View File

@ -52,9 +52,11 @@ public class FhirRequestBuilder {
* {@link FhirLoggingInterceptor} for log output.
*/
private FhirLoggingInterceptor logger = null;
private String source;
public FhirRequestBuilder(Request.Builder httpRequest) {
public FhirRequestBuilder(Request.Builder httpRequest, String source) {
this.httpRequest = httpRequest;
this.source = source;
}
/**
@ -253,9 +255,9 @@ public class FhirRequestBuilder {
error = (OperationOutcome) resource;
}
} catch (IOException ioe) {
throw new EFhirClientException("Error reading Http Response: " + ioe.getMessage(), ioe);
throw new EFhirClientException("Error reading Http Response from "+source+": " + ioe.getMessage(), ioe);
} catch (Exception e) {
throw new EFhirClientException("Error parsing response message: " + e.getMessage(), e);
throw new EFhirClientException("Error parsing response message from "+source+": " + e.getMessage(), e);
}
}
@ -290,12 +292,12 @@ public class FhirRequestBuilder {
}
}
} catch (IOException ioe) {
throw new EFhirClientException("Error reading Http Response", ioe);
throw new EFhirClientException("Error reading Http Response from "+source+": "+ioe.getMessage(), ioe);
} catch (Exception e) {
throw new EFhirClientException("Error parsing response message", e);
throw new EFhirClientException("Error parsing response message from "+source+": "+e.getMessage(), e);
}
if (error != null) {
throw new EFhirClientException("Error from server: " + ResourceUtilities.getErrorDescription(error), error);
throw new EFhirClientException("Error from "+source+": " + ResourceUtilities.getErrorDescription(error), error);
}
return feed;
}

View File

@ -112,6 +112,7 @@ public class FHIRToolingClient {
public void initialize(String baseServiceUrl) throws URISyntaxException {
base = baseServiceUrl;
client.setBase(base);
resourceAddress = new ResourceAddress(baseServiceUrl);
this.maxResultSetSize = -1;
}

View File

@ -23,6 +23,15 @@ public class Client {
private int retryCount;
private long timeout = DEFAULT_TIMEOUT;
private byte[] payload;
private String base;
public String getBase() {
return base;
}
public void setBase(String base) {
this.base = base;
}
public ToolingClientLogger getLogger() {
return logger;
@ -174,7 +183,7 @@ public class Client {
String message,
int retryCount,
long timeout) throws IOException {
return new FhirRequestBuilder(request)
return new FhirRequestBuilder(request, base)
.withLogger(fhirLoggingInterceptor)
.withResourceFormat(resourceFormat)
.withRetryCount(retryCount)
@ -190,7 +199,7 @@ public class Client {
String message,
int retryCount,
long timeout) throws IOException {
return new FhirRequestBuilder(request)
return new FhirRequestBuilder(request, base)
.withLogger(fhirLoggingInterceptor)
.withResourceFormat(resourceFormat)
.withRetryCount(retryCount)

View File

@ -50,9 +50,11 @@ public class FhirRequestBuilder {
* {@link FhirLoggingInterceptor} for log output.
*/
private FhirLoggingInterceptor logger = null;
private String source;
public FhirRequestBuilder(Request.Builder httpRequest) {
public FhirRequestBuilder(Request.Builder httpRequest, String source) {
this.httpRequest = httpRequest;
this.source = source;
}
/**
@ -249,14 +251,14 @@ public class FhirRequestBuilder {
error = (OperationOutcome) resource;
}
} catch (IOException ioe) {
throw new EFhirClientException("Error reading Http Response: " + ioe.getMessage(), ioe);
throw new EFhirClientException("Error reading Http Response from "+source+": " + ioe.getMessage(), ioe);
} catch (Exception e) {
throw new EFhirClientException("Error parsing response message: " + e.getMessage(), e);
throw new EFhirClientException("Error parsing response message from "+source+": " + e.getMessage(), e);
}
}
if (error != null) {
throw new EFhirClientException("Error from server: " + ResourceUtilities.getErrorDescription(error), error);
throw new EFhirClientException("Error from "+source+": " + ResourceUtilities.getErrorDescription(error), error);
}
return resource;
@ -284,12 +286,12 @@ public class FhirRequestBuilder {
}
}
} catch (IOException ioe) {
throw new EFhirClientException("Error reading Http Response", ioe);
throw new EFhirClientException("Error reading Http Response from "+source+":"+ioe.getMessage(), ioe);
} catch (Exception e) {
throw new EFhirClientException("Error parsing response message", e);
throw new EFhirClientException("Error parsing response message from "+source+": "+e.getMessage(), e);
}
if (error != null) {
throw new EFhirClientException("Error from server: " + ResourceUtilities.getErrorDescription(error), error);
throw new EFhirClientException("Error from "+source+": " + ResourceUtilities.getErrorDescription(error), error);
}
return feed;
}