title: Changing a 404 response for REST API to a 200 empty response
body: <p>I have a Spring Boot application written in Java that is a REST API.  This service (Svc A) calls a REST API service (Svc B) with is also a Spring Boot Application written in Java.  Svc B returns a 404 status code when no data was found.  I need to change this response to a 200 status code and return an empty response object.  I am not sure if or how to do this.</p>
  
  <p>I can catch the error and determine if the 404 is this no data found error.  However, I don't know how to change the response to a 200 empty response.
  I am using a FeignClient to call the service.  This is the error code that catches the 404:</p>
  
  <pre><code>@Component
  public class FeignErrorDecoder implements ErrorDecoder {
  
      Logger logger = LoggerFactory.getLogger(this.getClass());
  
      @Override
      public Exception decode(String methodKey, Response response) {
          Reader reader = null;
          String messageText = null;
          switch (response.status()){
              case 400:
                  logger.error("Status code " + response.status() + ", methodKey = " + methodKey);
              case 404:
              {
                  logger.error("Error took place when using Feign client to send HTTP Request. Status code " + response.status() + ", methodKey = " + methodKey);
                  try {
                      reader = response.body().asReader();
                      //Easy way to read the stream and get a String object
                      String result = CharStreams.toString(reader);
                      logger.error("RESPONSE BODY: " + result);
                      ObjectMapper mapper = new ObjectMapper();
                      //just in case you missed an attribute in the Pojo
                      mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
                      //init the Pojo
                      ExceptionMessage exceptionMessage = mapper.readValue(result,
                              ExceptionMessage.class);
  
                      messageText = exceptionMessage.getMessage();
                      logger.info("message: " + messageText);
  
                  } catch(IOException ex) {
                      logger.error(ex.getMessage());
                  }
                  finally {
                      try {
  
                          if (reader != null)
                              reader.close();
  
                      } catch (IOException e) {
                          e.printStackTrace();
                      }
                  }
  
                  return new ResponseStatusException(HttpStatus.valueOf(200), messageText);
              }
              default:
                  return new Exception(response.reason());
          }
      }
  }
  </code></pre>
  
  <p>I can change the status code to a 200 and it returns a 200 but I need to the response to have an empty response object.
  The above code will return this response body of an error response object:</p>
  
  <pre><code>{
     "statusCd" : "200",
     "message" : "The Location not found for given Location Number and Facility Type Code",
     "detailDesc" : "The Location not found for given Location Number and Facility Type Code. Error Timestamp : 2020-01-31 18:19:13"
  }
  </code></pre>
  
  <p>I need it to return a response body like this:
  200 - Empty Response</p>
  
  <pre><code>{
    "facilityNumber": "923",
    "facilityTimeZone": null,
    "facilityAbbr": null,
    "scheduledOperations": []
  }
  </code></pre>