MockServer enables easy mocking of any system you integrate with via HTTP or HTTPS with clients written in Java, JavaScript and Ruby. MockServer also includes a proxy that introspects all proxied traffic including encrypted SSL traffic and supports Port Forwarding, Web Proxying (i.e. HTTP proxy), HTTPS Tunneling Proxying (using HTTP CONNECT) and SOCKS Proxying (i.e. dynamic port forwarding).
When the java MockServerClient cannot connect to the mock server, in our case started by node, an exception is thrown. The type of exception is RuntimeException which has a cause of ConnectException.
In order to retry the operation we currently have to catch any exceptions in a catch block and then check the exception's cause before decided wether to retry or fail. This is bad as our code is now coupled to internal behaviours of the mock server client.
Can the mock server client be updated so that it throws a more appropriate exception, e.g. MockServerCommunicationException or something of that ilk which we can then use?
example code:
private void createMockServerClient() {
int attemptsRemaining = 5;
while (attemptsRemaining) {
try {
mockServerClient = new MockServerClient(MOCK_SERVER_HOST, MOCK_SERVER_PORT)
mockServerClient.reset()
break;
} catch (Exception caught) {
if (!(caught.cause instanceof ConnectException)) {
throw caught
}
attemptsRemaining--;
if (!attemptsRemaining) {
throw caught
}
println "Retrying connection to mock server, attempts remaining: ${attemptsRemaining}"
Thread.sleep(250)
}
}
}
I'd rather this was something like:
private void createMockServerClient() {
int attemptsRemaining = 5;
while (attemptsRemaining) {
try {
mockServerClient = new MockServerClient(MOCK_SERVER_HOST, MOCK_SERVER_PORT)
mockServerClient.reset()
break;
} catch (MockServerConnectionException caught) {
attemptsRemaining--;
if (!attemptsRemaining) {
throw caught
}
println "Retrying connection to mock server, attempts remaining: ${attemptsRemaining}"
Thread.sleep(250)
}
}
}
When the java MockServerClient cannot connect to the mock server, in our case started by node, an exception is thrown. The type of exception is RuntimeException which has a cause of ConnectException.
In order to retry the operation we currently have to catch any exceptions in a catch block and then check the exception's cause before decided wether to retry or fail. This is bad as our code is now coupled to internal behaviours of the mock server client.
Can the mock server client be updated so that it throws a more appropriate exception, e.g. MockServerCommunicationException or something of that ilk which we can then use?
example code:
I'd rather this was something like: