Skip to content

Commit 8096337

Browse files
committed
Handle timeouts in WebClientFilter and ArenaForvalterClient
Add TimeoutException handling in WebClientFilter for improved error messaging and status codes. Update ArenaForvalterClient to include timeout on WebClient calls with a 30-second limit, and provide detailed error messages on timeout exceptions.
1 parent 40938b9 commit 8096337

File tree

3 files changed

+36
-7
lines changed

3 files changed

+36
-7
lines changed

apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/arenaforvalter/ArenaForvalterClient.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,20 @@
1616
import no.nav.dolly.domain.resultset.dolly.DollyPerson;
1717
import no.nav.dolly.util.IdentTypeUtil;
1818
import no.nav.dolly.util.TransactionHelperService;
19+
import no.nav.testnav.libs.reactivecore.utils.WebClientFilter;
1920
import org.apache.commons.lang3.StringUtils;
2021
import org.springframework.stereotype.Service;
2122
import reactor.core.publisher.Flux;
2223
import reactor.core.publisher.Mono;
2324

25+
import java.time.Duration;
2426
import java.util.List;
2527
import java.util.stream.Collectors;
2628

2729
import static java.util.Objects.nonNull;
2830
import static no.nav.dolly.bestilling.arenaforvalter.utils.ArenaStatusUtil.AAP;
2931
import static no.nav.dolly.bestilling.arenaforvalter.utils.ArenaStatusUtil.AAP115;
32+
import static no.nav.dolly.bestilling.arenaforvalter.utils.ArenaStatusUtil.ANDREFEIL;
3033
import static no.nav.dolly.bestilling.arenaforvalter.utils.ArenaStatusUtil.BRUKER;
3134
import static no.nav.dolly.bestilling.arenaforvalter.utils.ArenaStatusUtil.DAGPENGER;
3235
import static no.nav.dolly.bestilling.arenaforvalter.utils.ArenaStatusUtil.fmtResponse;
@@ -66,6 +69,9 @@ public Flux<ClientFuture> gjenopprett(RsDollyUtvidetBestilling bestilling, Dolly
6669
BestillingProgress::setArenaforvalterStatus, initStatus);
6770
})
6871
.flatMap(miljoer -> doArenaOpprett(ordre, dollyPerson.getIdent(), miljoer)
72+
.timeout(Duration.ofSeconds(30))
73+
.onErrorResume(error ->
74+
Mono.just(fmtResponse(miljoer, ANDREFEIL, WebClientFilter.getMessage(error))))
6975
.map(status -> futurePersist(progress, status))));
7076
}
7177

@@ -94,7 +100,7 @@ private Mono<String> doArenaOpprett(Arenadata arenadata, String ident, List<Stri
94100
arenaDagpengerService.sendDagpenger(arenadata, arenaOperasjoner, ident, miljoe)
95101
.map(dagpengerStatus -> fmtResponse(miljoe, DAGPENGER, dagpengerStatus))
96102
));
97-
} else {
103+
} else {
98104
return Flux.just(fmtResponse(miljoe, BRUKER, NOT_SUPPORTED));
99105
}
100106
})

apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/arenaforvalter/utils/ArenaStatusUtil.java

+11-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import reactor.core.publisher.Flux;
1212
import reactor.core.publisher.Mono;
1313

14+
import java.util.Collection;
1415
import java.util.Map;
1516
import java.util.stream.Collectors;
1617

@@ -29,6 +30,7 @@ public class ArenaStatusUtil {
2930
public static final String AAP115 = "AAP115";
3031
public static final String AAP = "AAP";
3132
public static final String DAGPENGER = "DAGP";
33+
public static final String ANDREFEIL = "ARENA Oppretting Feil=";
3234

3335
public static Mono<String> getDagpengerStatus(ArenaNyeDagpengerResponse response, ErrorStatusDecoder errorStatusDecoder) {
3436

@@ -37,7 +39,7 @@ public static Mono<String> getDagpengerStatus(ArenaNyeDagpengerResponse response
3739
.map(status -> errorStatusDecoder.getErrorText(response.getStatus(), getMessage(response.getFeilmelding()))),
3840
Flux.fromIterable(response.getNyeDagp())
3941
.filter(nyDagP -> nonNull(nyDagP.getNyeDagpResponse()))
40-
.map(nyDagP -> "JA".equals(nyDagP.getNyeDagpResponse().getUtfall()) ?
42+
.map(nyDagP -> "JA".equals(nyDagP.getNyeDagpResponse().getUtfall()) ?
4143
"OK" :
4244
encodeStatus(ArenaUtils.AVSLAG + nyDagP.getNyeDagpResponse().getBegrunnelse()))
4345
.collect(Collectors.joining()),
@@ -78,9 +80,16 @@ public static Mono<String> getAapStatus(AapResponse response, ErrorStatusDecoder
7880
}
7981
}
8082

83+
public static String fmtResponse(Collection<String> miljoer, String system, String status) {
84+
85+
return miljoer.stream()
86+
.map(miljo -> fmtResponse(miljo, system, status))
87+
.collect(Collectors.joining(","));
88+
}
89+
8190
public static String fmtResponse(String miljoe, String system, String status) {
8291

83-
return String.format(MILJOE_FMT, miljoe, system, encodeStatus(status));
92+
return MILJOE_FMT.formatted(miljoe, system, encodeStatus(status));
8493
}
8594

8695
public static String getMessage(String jsonFeilmelding) {

libs/reactive-core/src/main/java/no/nav/testnav/libs/reactivecore/utils/WebClientFilter.java

+18-4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import java.net.SocketException;
1313
import java.nio.charset.StandardCharsets;
14+
import java.util.concurrent.TimeoutException;
1415

1516
@Slf4j
1617
@UtilityClass
@@ -46,21 +47,34 @@ public static String getMessage(Throwable throwable) {
4647
return requestException.getCause().toString();
4748
}
4849

50+
} else if (throwable instanceof TimeoutException) {
51+
52+
return "Mottaker svarer ikke, eller har for lang svartid.";
53+
4954
} else {
5055
return throwable.getMessage();
5156
}
5257
}
5358

5459
public static HttpStatus getStatus(Throwable throwable) {
5560

56-
return throwable instanceof WebClientResponseException webClientResponseException ?
57-
HttpStatus.valueOf(webClientResponseException.getStatusCode().value()) :
58-
HttpStatus.INTERNAL_SERVER_ERROR;
61+
if (throwable instanceof WebClientResponseException webClientResponseException) {
62+
return HttpStatus.valueOf(webClientResponseException.getStatusCode().value());
63+
64+
} else if (throwable instanceof TimeoutException) {
65+
return HttpStatus.REQUEST_TIMEOUT;
66+
67+
} else {
68+
return HttpStatus.INTERNAL_SERVER_ERROR;
69+
}
5970
}
6071

6172
public static void logErrorMessage(Throwable throwable) {
6273

63-
if (!(throwable instanceof WebClientResponseException)) {
74+
if ((throwable instanceof WebClientResponseException webClientResponseException)) {
75+
log.error("%s, %s".formatted(throwable.getMessage(),
76+
webClientResponseException.getResponseBodyAsString()), throwable);
77+
} else {
6478
log.error(throwable.getMessage(), throwable);
6579
}
6680
}

0 commit comments

Comments
 (0)