Skip to content

Commit

Permalink
Added reference to all exceptions / error responses
Browse files Browse the repository at this point in the history
  • Loading branch information
oharsta committed Jan 19, 2023
1 parent c92753e commit 8c541a8
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/main/java/generiek/api/EnrollmentEndpoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.*;
import org.springframework.http.client.OkHttp3ClientHttpRequestFactory;
import org.springframework.lang.Nullable;
import org.springframework.util.CollectionUtils;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
Expand Down Expand Up @@ -266,7 +265,7 @@ public ResponseEntity<Map<String, Object>> start(
if (code >= 400) {
//Body can be immutable
Map<String, Object> copy = new HashMap<>(results.getBody());
copy.put("reference", String.valueOf(Math.round(Math.random() * 10000)));
copy.put("reference", referenceCorrelation());
LOG.error(String.format("Error in registration results %s for enrollmentRequest %s", copy, enrollmentRequest));
return ResponseEntity.ok(copy);
}
Expand All @@ -276,6 +275,10 @@ public ResponseEntity<Map<String, Object>> start(
}
}

private String referenceCorrelation() {
return String.valueOf(Math.round(Math.random() * 10000));
}

/*
* Called by the Broker on behalf of the test user
*/
Expand Down Expand Up @@ -475,10 +478,12 @@ private EnrollmentRequest refreshTokens(EnrollmentRequest enrollmentRequest) {
}

private ResponseEntity<Map<String, Object>> errorResponseEntity(String description, HttpStatusCodeException e) {
LOG.error(description, e);
String reference = referenceCorrelation();
LOG.error(String.format("%s, reference: %s", description, reference), e);

Map<String, Object> results = new HashMap<>();
results.put("error", true);
results.put("reference", reference);
results.put("message", e.getMessage());
results.put("details", e.getResponseBodyAsString());
results.put("description", description);
Expand Down

0 comments on commit 8c541a8

Please sign in to comment.