title: How implement Error decoder for multiple feign clients
body: <p>I have multiple feign clients in a Spring Boot application. I am using a Controller Advice for handling custom exceptions for each feign client. </p>
  
  <p>Here my controller advice that handles two custom exceptions (one for each client: client1 and client2):</p>
  
  <pre><code>   @ControllerAdvice
      public class ExceptionTranslator implements ProblemHandling {
           @ExceptionHandler
          public ResponseEntity&lt;Problem&gt; handleCustomClient1Exception(CustomException1 ex, NativeWebRequest request) {
              Problem problem = Problem.builder()
                      .title(ex.getTitle())
                      .detail(ex.getMessage())
                      .status(ex.getStatusType())
                      .code(ex.getCode())
                      .build();
              return create(ex, problem, request);
          }
           @ExceptionHandler
          public ResponseEntity&lt;Problem&gt; handleCustomClient2Exception(CustomException2 ex, NativeWebRequest request) {
                  Problem problem = Problem.builder()
                          .title(ex.getTitle())
                          .detail(ex.getMessage())
                          .status(ex.getStatusType())
                          .code(ex.getCode())
                          .build();
                  return create(ex, problem, request);
              }
          }
  </code></pre>
  
  <p>I have implemented an error decoder for feign client1.</p>
  
  <pre><code>public class ClientErrorDecoder implements ErrorDecoder {
      final ObjectMapper mapper;
  
  
      public ClientErrorDecoder() {
          this.mapper = new ObjectMapper();
      }
  
  @Override
  public Exception decode(String methodKey, Response response) {
      ExceptionDTO exceptionDTO;
  
      try {
          exceptionDTO = mapper.readValue(response.body().asInputStream(), ExceptionDTO.class);
      } catch (IOException e) {
          throw new RuntimeException("Failed to process response body.", e);
      }
  
  
      return new CustomException1(exceptionDTO.getDetail(), exceptionDTO.getCode(), exceptionDTO.getTitle(), exceptionDTO.getStatus());
  
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>I have also configured feign for using that error decoder for that specific client like this:</p>
  
  <pre><code>feign:
  client:
      config:
          client1:
              errorDecoder: feign.codec.ErrorDecoder.Default
  </code></pre>
  
  <p>My question is: <strong>what is the best approach for handling more than one feign client exceptions? Should I use the same error decoder and treat their responses as a generic exception? Or should I create an error decoder for each feign client?</strong></p>