I am calling Restservice through RestTemplate through below code :
ResponseEntity response = new RestTemplate().postForEntity(url, request, String.class);
whenever something wrong comes from Client , it throws below error :
org.springframework.web.client.HttpClientErrorException: 400 Bad Request
at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:85)
at org.springframework.web.client.RestTemplate.handleResponse(RestTemplate.java:708)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:661)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:621)
at org.springframework.web.client.RestTemplate.postForEntity(RestTemplate.java:415)
But when I hit directly the same input request through SOAPUI or Postman ,I get this error like below :
<Errors>
<Error ErrorCode="YFS10003" ErrorDescription="YFS:Invalid Order" ErrorUniqueExceptionId="10.148.201.9815264936514610000000000060" HttpCode="400">
<Attribute Name="ErrorDescription" Value="YFS:Invalid Order"/>
<Attribute Name="ErrorUniqueExceptionId" Value="10.148.201.9815264936514610000000000060"/>
<Attribute Name="ErrorCode" Value="YFS10003"/>
<Attribute Name="HttpCode" Value="400"/>
</Error>
</Errors>
What I need is , how can I store or catch above exception/error what is coming through client in code and print to have more detailed knowledge about why error came rather than getting a generic error as 400 Bad request.
Is there is way through ResponseErrorHandler class ?
Thanks in advance.
application/jsonon the header it might return xml.Try putting header in SOAPUI or POSTMan - cosmos