Search in sources :

Example 1 with FhirException

use of com.b2international.snowowl.fhir.core.exceptions.FhirException in project snow-owl by b2ihealthcare.

the class AbstractFhirController method handle.

/**
 * Generic <b>Internal Server Error</b> exception handler, serving as a fallback for RESTful client calls.
 *
 * @param ex
 * @return {@link OperationOutcome} instance with detailed messages
 */
@ExceptionHandler
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
@ResponseBody
public OperationOutcome handle(final Exception ex) {
    if (Throwables.getRootCause(ex).getMessage().toLowerCase().contains("broken pipe")) {
        // socket is closed, cannot return any response
        return null;
    } else {
        LOG.error("Exception during processing of a request", ex);
        FhirException fhirException = FhirException.createFhirError(GENERIC_USER_MESSAGE + " Exception: " + ex.getMessage(), OperationOutcomeCode.MSG_BAD_SYNTAX);
        return fhirException.toOperationOutcome();
    }
}
Also used : FhirException(com.b2international.snowowl.fhir.core.exceptions.FhirException) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 2 with FhirException

use of com.b2international.snowowl.fhir.core.exceptions.FhirException in project snow-owl by b2ihealthcare.

the class AbstractFhirController method handle.

/**
 * Exception handler converting any {@link JsonMappingException} to an <em>HTTP 400</em>.
 *
 * @param ex
 * @return {@link OperationOutcome} instance with detailed messages
 */
@ExceptionHandler
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ResponseBody
public OperationOutcome handle(HttpMessageNotReadableException ex) {
    LOG.trace("Exception during processing of a JSON document", ex);
    FhirException fhirException = FhirException.createFhirError(GENERIC_USER_MESSAGE + " Exception: " + ex.getMessage(), OperationOutcomeCode.MSG_CANT_PARSE_CONTENT);
    return fhirException.toOperationOutcome();
}
Also used : FhirException(com.b2international.snowowl.fhir.core.exceptions.FhirException) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 3 with FhirException

use of com.b2international.snowowl.fhir.core.exceptions.FhirException in project snow-owl by b2ihealthcare.

the class AbstractFhirController method handle.

@ExceptionHandler
@ResponseStatus(HttpStatus.UNAUTHORIZED)
@ResponseBody
public ResponseEntity<OperationOutcome> handle(final UnauthorizedException ex) {
    FhirException fhirException = FhirException.createFhirError(ex.getMessage(), OperationOutcomeCode.MSG_AUTH_REQUIRED);
    OperationOutcome body = fhirException.toOperationOutcome();
    HttpHeaders headers = new HttpHeaders();
    headers.add("WWW-Authenticate", "Basic");
    headers.add("WWW-Authenticate", "Bearer");
    return new ResponseEntity<>(body, headers, HttpStatus.UNAUTHORIZED);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) FhirException(com.b2international.snowowl.fhir.core.exceptions.FhirException) OperationOutcome(com.b2international.snowowl.fhir.core.model.OperationOutcome) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

FhirException (com.b2international.snowowl.fhir.core.exceptions.FhirException)3 ExceptionHandler (org.springframework.web.bind.annotation.ExceptionHandler)3 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)3 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)3 OperationOutcome (com.b2international.snowowl.fhir.core.model.OperationOutcome)1 HttpHeaders (org.springframework.http.HttpHeaders)1 ResponseEntity (org.springframework.http.ResponseEntity)1