|
|
@ -209,13 +209,23 @@ public class TbHttpClient { |
|
|
semaphore.release(); |
|
|
semaphore.release(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
onFailure.accept(processException(msg, throwable), throwable); |
|
|
onFailure.accept(processException(msg, throwable), processThrowable(throwable)); |
|
|
}); |
|
|
}); |
|
|
} catch (InterruptedException e) { |
|
|
} catch (InterruptedException e) { |
|
|
log.warn("Timeout during waiting for reply!", e); |
|
|
log.warn("Timeout during waiting for reply!", e); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private Throwable processThrowable(Throwable origin) { |
|
|
|
|
|
if (origin instanceof WebClientResponseException restClientResponseException |
|
|
|
|
|
&& restClientResponseException.getStatusCode().is2xxSuccessful()) { |
|
|
|
|
|
// return cause instead of original exception in case 2xx status code
|
|
|
|
|
|
// this will provide meaningful error message to the user
|
|
|
|
|
|
return new RuntimeException(restClientResponseException.getCause()); |
|
|
|
|
|
} |
|
|
|
|
|
return origin; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public URI buildEncodedUri(String endpointUrl) { |
|
|
public URI buildEncodedUri(String endpointUrl) { |
|
|
if (endpointUrl == null) { |
|
|
if (endpointUrl == null) { |
|
|
throw new RuntimeException("Url string cannot be null!"); |
|
|
throw new RuntimeException("Url string cannot be null!"); |
|
|
@ -287,9 +297,6 @@ public class TbHttpClient { |
|
|
metaData.putValue(STATUS, restClientResponseException.getStatusText()); |
|
|
metaData.putValue(STATUS, restClientResponseException.getStatusText()); |
|
|
metaData.putValue(STATUS_CODE, restClientResponseException.getStatusCode().value() + ""); |
|
|
metaData.putValue(STATUS_CODE, restClientResponseException.getStatusCode().value() + ""); |
|
|
metaData.putValue(ERROR_BODY, restClientResponseException.getResponseBodyAsString()); |
|
|
metaData.putValue(ERROR_BODY, restClientResponseException.getResponseBodyAsString()); |
|
|
if (restClientResponseException.getStatusCode().is2xxSuccessful()) { |
|
|
|
|
|
metaData.putValue(ERROR, metaData.getValue(ERROR) + ". Cause: " +restClientResponseException.getCause().getMessage()); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
return TbMsg.transformMsgMetadata(origMsg, metaData); |
|
|
return TbMsg.transformMsgMetadata(origMsg, metaData); |
|
|
} |
|
|
} |
|
|
|