in Education by
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)

1 Answer

0 votes
by
Not clear what is your issue, but I'll try to explain some things. You definitely might not need that custom ErrorHandler, because a default one is pretty good and in the end it just does this: protected void handleError(ClientHttpResponse response, HttpStatus statusCode) throws IOException { String statusText = response.getStatusText(); HttpHeaders headers = response.getHeaders(); byte[] body = getResponseBody(response); Charset charset = getCharset(response); switch (statusCode.series()) { case CLIENT_ERROR: throw HttpClientErrorException.create(statusCode, statusText, headers, body, charset); case SERVER_ERROR: throw HttpServerErrorException.create(statusCode, statusText, headers, body, charset); default: throw new UnknownHttpStatusCodeException(statusCode.value(), statusText, headers, body, charset); } } So, it parses a response and throws respective exception to the caller. If you need to react somehow to this or that exception while calling that REST service, you need to consider to use an ExpressionEvaluatingRequestHandlerAdvice for the . This way an exception propagated from the DefaultResponseErrorHandler can be sent to some failureChannel for possible logic how to react to this exception. See more info in the Docs: https://docs.spring.io/spring-integration/docs/current/reference/html/#message-handler-advice-chain If that is not what you expect, please, rephrase your question because it isn't clear for me yet... Thanks for understanding.

Related questions

0 votes
    What is the most idiomatic way to handle multiple errors in go? Should I try to wrap the error ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 20, 2022 in Education by JackTerrance
0 votes
    How do you handle a situation in which unexpected errors occur during the execution of a script?...
asked Oct 19, 2020 in Technology by JackTerrance
0 votes
    The capability of your build system to handle an increase in the amount of code that it integrates and ... Build performance Select the correct answer from above options...
asked Nov 26, 2021 in Education by JackTerrance
0 votes
    I have 2 JMS queues and my application subscribes to both of them with Jms.messageDrivenChannelAdapter(...) ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 30, 2022 in Education by JackTerrance
0 votes
    I'm using Spring.net with NHiberante (HibernateTemplate) to implement my DAO's. I also have some ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 16, 2022 in Education by JackTerrance
0 votes
    I'm using Spring.net with NHiberante (HibernateTemplate) to implement my DAO's. I also have some ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 16, 2022 in Education by JackTerrance
+1 vote
    Which are the modules of Data Access/ integration layer in Spring? A - JDBC, ORM, OXM, JMS, Transactions B - JDBC, ORM, OXM, JMS C - JDBC, ORM, Web, Beans D - JDBC, ORM, OXM, JMS...
asked Oct 14, 2020 in Technology by JackTerrance
0 votes
    I have set up Vue so that I have a top level AppLayout component which just includes a Navigation Menu ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 20, 2022 in Education by JackTerrance
0 votes
    I have implemented exception handling as mentioned in below link How to pass error message to error view in ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 20, 2022 in Education by JackTerrance
0 votes
    Almost all MPI routines return an error handler. However, a communication error usually crashes the program at ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 20, 2022 in Education by JackTerrance
0 votes
    How should I handle this exception for API data requester? The Dostuff1,2,3 is 3 different functions that ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    How should I handle this exception for API data requester? The Dostuff1,2,3 is 3 different functions that ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    I inserted in PostgreSQL table an UUID created with go.uuid : import ( "github.com/satori/go.uuid" ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    I inserted in PostgreSQL table an UUID created with go.uuid : import ( "github.com/satori/go.uuid" ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 1, 2022 in Education by JackTerrance
0 votes
    How should I handle this exception for API data requester? The Dostuff1,2,3 is 3 different functions that ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 24, 2022 in Education by JackTerrance
...