How do I propogate an exception thrown in a call to a downstream service to the caller method?
I have a service that calculates something and throws an exception in case of error:
{ "timestamp": "2019-03-12T08:21:05.316+0000", "status": 500, "error": "Internal Server Error", "message": "VAKUUTUSVUOSI.MAKSUEHTO is null or not numeric. Can't be added to due date.", "path": "/rules/yk32/deducePaymentDueDate" } But the calling service displays this exception:
{ "timestamp": "2019-03-12T08:30:22.912+0000", "status": 500, "error": "Internal Server Error", "message": "500 null", "path": "/calculation/annual/payment" } How do I get the caller method also to display the message that the service throws "/rules/yk32/deducePaymentDueDate" instead of "Internal Server Error"?
Calling method:
LocalDate paymentDueDate = ykServiceAdapter.yk32DeducePaymentDueDate(requestDTO); Calling function in the ykServiceadapter:
public LocalDate yk32DeducePaymentDueDate(Yk32RequestDTO requestDTO) { ResponseEntity<LocalDate> re; HttpEntity<?> entity = new HttpEntity<>(requestDTO); try { re = getRestTemplate().exchange( buildServiceUrl(externalServiceConfig, RULE_YK32, DEDUCE_PAYMENT_DUEDATE), HttpMethod.POST, entity, new ParameterizedTypeReference<LocalDate>() { }); return re.getBody(); } catch (HttpClientErrorException ex) { if (HttpStatus.NOT_FOUND.equals(ex.getStatusCode())) { return null; } else { throw ex; } } }