Audit Resilience4j HTTP response status codes

Viewed 93

In present situation I can write in DB only result

  • true - is good
  • false - is bad

How can I get http code and analyze it?

For example, if response code is 204 or 400 for me it's good response. All others are bad... And write it to DB.

Now I'm reading about ErrorDecoder (in Feign), am I looking in the right direction? But I would not want to change the logic of ALL FeignClient, only one method

@Slf4j
@Service
@RequiredArgsConstructor
public class TestService {

  private final DataBaseService dataBaseService;
  private final TestRepository testRepository;
  private final TestFeign testFeign;

  @Async
  @Retry(name = "testRetry", fallbackMethod = "testFallback")
  public void rboLimitComplexSetting(UUID uuid, TestRequest testRequest) {
    log.info("Отправка запроса в RBO limitId = {} ", limitId);
    testFeign.test(testRequest);
    addLog(uuid, true);
  }

  private void testFallback(UUID uuid, TestRequest testRequest, RuntimeException ex) {
    addLog(limitId, false);
  }

  private void addLog(UUID uuid, boolean result) {
    var entity = dataBaseService.findById(uuid);
    entity.setResult(result);

    testRepository.save(entity);
  }
}
0 Answers
Related