Search in sources :

Example 1 with OperationOutcomeError

use of uk.nhs.adaptors.scr.exceptions.OperationOutcomeError in project summary-care-record-api by NHSDigital.

the class OperationOutcomeExceptionHandler method handleAllExceptions.

@ExceptionHandler(Exception.class)
public ResponseEntity<Object> handleAllExceptions(Exception ex) {
    LOGGER.error("Error occurred: {}", ex.getMessage());
    OperationOutcome operationOutcome;
    HttpStatus httpStatus;
    if (ex instanceof OperationOutcomeError) {
        OperationOutcomeError error = (OperationOutcomeError) ex;
        operationOutcome = error.getOperationOutcome();
        httpStatus = error.getStatusCode();
    } else {
        operationOutcome = createOperationOutcome(EXCEPTION, ERROR, ex.getMessage());
        httpStatus = INTERNAL_SERVER_ERROR;
    }
    return errorResponse(new HttpHeaders(), httpStatus, operationOutcome);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) HttpStatus(org.springframework.http.HttpStatus) OperationOutcomeUtils.createOperationOutcome(uk.nhs.adaptors.scr.utils.OperationOutcomeUtils.createOperationOutcome) OperationOutcome(org.hl7.fhir.r4.model.OperationOutcome) OperationOutcomeError(uk.nhs.adaptors.scr.exceptions.OperationOutcomeError) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler) ResponseEntityExceptionHandler(org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler)

Aggregations

OperationOutcome (org.hl7.fhir.r4.model.OperationOutcome)1 HttpHeaders (org.springframework.http.HttpHeaders)1 HttpStatus (org.springframework.http.HttpStatus)1 ExceptionHandler (org.springframework.web.bind.annotation.ExceptionHandler)1 ResponseEntityExceptionHandler (org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler)1 OperationOutcomeError (uk.nhs.adaptors.scr.exceptions.OperationOutcomeError)1 OperationOutcomeUtils.createOperationOutcome (uk.nhs.adaptors.scr.utils.OperationOutcomeUtils.createOperationOutcome)1