I have followed the link Spring integration: handle http error with oubound gateway
But I don't have full understanding.
I looked at 3. Implementing a ResponseErrorHandler of
https://www.baeldung.com/spring-rest-template-error-handling, but not sure what to do at // handle SERVER_ERROR etc
My flow:
Rest end point calls gateway method and then the below.
....
The java class. Thought there is not much implementation, it looks like without this, I am not getting the error message thrown by external service.
Is there a way I can get rid of this class, as it is almost default [though added CLIENT and SERVER error check, based on baeldung article?
public class ErrorHandler extends DefaultResponseErrorHandler {
@Override
public boolean hasError(ClientHttpResponse response) throws IOException {
return (
response.getStatusCode().series() == HttpStatus.Series.CLIENT_ERROR
|| response.getStatusCode().series() == HttpStatus.Series.SERVER_ERROR);
}
@Override
public void handleError(ClientHttpResponse response) throws IOException { /* Handle Exceptions */
}
}
I see suggestions to use Advices. can I ask for an example? [not sure if this is spring rest or spring integration]
EDIT 1:
I am calling an external service. It can give an error message like below
{
"code": "F01",
"userMessage": "The is some data error....",
"parameters": {}
}
Before I added error-handler to http-outbound-gateway, I was always getting response as "Bad Request" [and missing a clear message like above]
After adding error-handler and the class, I am able to forward, whatever error message, external service is giving [in its response body]. This is acceptable, but I am not having any implementation in handleError [like you answered]. In such case, is there a way of getting rid of this class and utilize any OOTB class? because I have no justification of why it is there [ may be I don't understand its importance].
P.S. @Artem Bilan, Your answer may suffice [if I need the class for my problem]
JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)