Skip to content

Commit

Permalink
objectMapper on error message from webclient & deploy to beta for tes…
Browse files Browse the repository at this point in the history
…ting
  • Loading branch information
Sander14121 committed Sep 20, 2024
1 parent fd30fee commit 375c338
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/CD.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ jobs:
strategy:
matrix:
org:
# - fintlabs-no
- ofk-no
- bfk-no
- afk-no
- fintlabs-no
# - ofk-no
# - bfk-no
# - afk-no
cluster:
- aks-api-fint-2022-02-08
# - aks-beta-fint-2021-11-23
# - aks-api-fint-2022-02-08
- aks-beta-fint-2021-11-23
include:
- org: fintlabs-no
cluster: aks-beta-fint-2021-11-23
Expand Down
15 changes: 14 additions & 1 deletion src/main/java/no/fint/betaling/claim/ClaimRestStatusService.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package no.fint.betaling.claim;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import no.fint.betaling.common.exception.ClientErrorException;
import no.fint.betaling.common.exception.ServerErrorException;
Expand Down Expand Up @@ -105,7 +107,8 @@ private void updateClaimOnFailure(Claim claim, Throwable error) {

String message = (error instanceof WebClientResponseException webClientError
&& StringUtils.hasText(webClientError.getResponseBodyAsString()))
? webClientError.getResponseBodyAsString() : error.getMessage();
? extractErrorMessageFromJson(webClientError.getResponseBodyAsString())
: error.getMessage();

log.error("Error updating claim {} {} with invoiceUri {}", claim.getOrderNumber(), claim.getClaimStatus(), claim.getInvoiceUri());
log.error("Claim status: {}", message);
Expand All @@ -115,6 +118,16 @@ private void updateClaimOnFailure(Claim claim, Throwable error) {
claimRepository.save(claim);
}

private String extractErrorMessageFromJson(String json) {
ObjectMapper mapper = new ObjectMapper();
try {
JsonNode jsonNode = mapper.readTree(json);
return jsonNode.has("message") ? jsonNode.get("message").asText() : "null";
}catch (Exception e){
return "Error in JSON-Parsing";
}
}

private Mono<ResponseEntity<Void>> evaluateResponse(ResponseEntity<Void> response, Claim claim) {
HttpStatusCode statusCode = response.getStatusCode();

Expand Down

0 comments on commit 375c338

Please sign in to comment.