Skip to content

Commit

Permalink
Enhance error handling in sykemelding validation.
Browse files Browse the repository at this point in the history
#deploy-test-sykemelding-api

Added error handling in SyfosmreglerPostValidateCommand to capture and log errors, assigning relevant HTTP status and message to ValidationResultDTO. This improves reliability and debuggability by providing more information about the error state during the sykemelding validation process. Additionally, updated ValidationResultDTO and included a new import in test cases for consistency.
  • Loading branch information
krharum committed Nov 29, 2024
1 parent 2c5ca0b commit 9346d66
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import lombok.RequiredArgsConstructor;
import no.nav.registre.testnorge.sykemelding.dto.ReceivedSykemeldingDTO;
import no.nav.testnav.libs.dto.sykemelding.v1.ValidationResultDTO;
import no.nav.testnav.libs.reactivecore.utils.WebClientFilter;
import org.springframework.http.HttpHeaders;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Mono;
Expand All @@ -26,6 +27,11 @@ public Mono<ValidationResultDTO> call() {
.header(HttpHeaders.AUTHORIZATION, "Bearer " + accessToken)
.bodyValue(receivedSykemelding)
.retrieve()
.bodyToMono(ValidationResultDTO.class);
.bodyToMono(ValidationResultDTO.class)
.doOnError(WebClientFilter::logErrorMessage)
.onErrorResume(error -> Mono.just(ValidationResultDTO.builder()
.httpStatus(WebClientFilter.getStatus(error))
.message(WebClientFilter.getMessage(error))
.build()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension;

import static org.junit.jupiter.api.Assertions.*;

@ExtendWith(MockitoExtension.class)
class SykemeldingValidateMappingStrategyTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.http.HttpStatus;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -16,6 +17,9 @@
@AllArgsConstructor
public class ValidationResultDTO {

private HttpStatus httpStatus;
private String message;

private AllowedValues status;
private List<Items> ruleHits;

Expand Down

0 comments on commit 9346d66

Please sign in to comment.