-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LCAM-985: Upgraded crime commons version and enabled micrometer tracing
- Loading branch information
1 parent
ef2e270
commit da02bab
Showing
7 changed files
with
19 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
@Value | ||
@Builder | ||
public class ErrorDTO { | ||
private String traceId; | ||
private String code; | ||
private String message; | ||
} |
14 changes: 9 additions & 5 deletions
14
.../main/java/uk/gov/justice/laa/crime/evidence/exception/CrimeEvidenceExceptionHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,36 @@ | ||
package uk.gov.justice.laa.crime.evidence.exception; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import org.springframework.web.bind.annotation.RestControllerAdvice; | ||
import uk.gov.justice.laa.crime.commons.exception.APIClientException; | ||
import uk.gov.justice.laa.crime.commons.tracing.TraceIdHandler; | ||
import uk.gov.justice.laa.crime.evidence.dto.ErrorDTO; | ||
|
||
|
||
@RestControllerAdvice | ||
@Slf4j | ||
@RestControllerAdvice | ||
@RequiredArgsConstructor | ||
public class CrimeEvidenceExceptionHandler { | ||
|
||
private static ResponseEntity<ErrorDTO> buildErrorResponse(HttpStatus status, String errorMessage) { | ||
private final TraceIdHandler traceIdHandler; | ||
|
||
private static ResponseEntity<ErrorDTO> buildErrorResponse(HttpStatus status, String errorMessage, String traceId) { | ||
return new ResponseEntity<>(ErrorDTO.builder().code(status.toString()).message(errorMessage).build(), status); | ||
} | ||
|
||
@ExceptionHandler(APIClientException.class) | ||
public ResponseEntity<ErrorDTO> handleApiClientError(APIClientException ex) { | ||
log.error("APIClientException: ", ex); | ||
return buildErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR, ex.getMessage()); | ||
return buildErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR, ex.getMessage(), traceIdHandler.getTraceId()); | ||
} | ||
|
||
@ExceptionHandler(CrimeEvidenceDataException.class) | ||
public ResponseEntity<ErrorDTO> handleCrimeEvidenceDataException(CrimeEvidenceDataException ex) { | ||
log.error("CrimeEvidenceDataException: ", ex); | ||
return buildErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR, ex.getMessage()); | ||
return buildErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR, ex.getMessage(), traceIdHandler.getTraceId()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters