use of ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException in project gpconnect-demonstrator by nhsconnect.
the class FhirRequestGenericIntercepter method preProcessOutgoingException.
/**
* Listens for any exceptions thrown. In the case of invalid parameters, we
* need to catch this and throw it as a UnprocessableEntityException.
*
* @param theRequestDetails
* @param theException
* @param theServletRequest
* @return UnprocessableEntityException if a InvalidRequestException was
* thrown.
* @throws javax.servlet.ServletException
*/
@Override
public BaseServerResponseException preProcessOutgoingException(RequestDetails theRequestDetails, Throwable theException, HttpServletRequest theServletRequest) throws ServletException {
LOG.info("Response Exception");
LOG.info(theException.getMessage());
LOG.info("stackTrace: ", theException);
// how else to pick up on just the relevant exceptions!
if (theException instanceof InvalidRequestException && theException.getMessage().contains("Invalid attribute value")) {
return OperationOutcomeFactory.buildOperationOutcomeException(new UnprocessableEntityException(theException.getMessage()), SystemCode.INVALID_PARAMETER, IssueType.INVALID);
}
if (theException instanceof InvalidRequestException && theException.getMessage().contains("Unknown resource in URI")) {
return OperationOutcomeFactory.buildOperationOutcomeException(new ResourceNotFoundException(theException.getMessage()), SystemCode.BAD_REQUEST, IssueType.INVALID);
}
if (theException instanceof InvalidRequestException && theException.getMessage().contains("Can not have multiple date range parameters for the same param ")) {
return OperationOutcomeFactory.buildOperationOutcomeException(new UnprocessableEntityException(theException.getMessage()), SystemCode.INVALID_PARAMETER, IssueType.INVALID);
}
if (theException instanceof DataFormatException) {
return OperationOutcomeFactory.buildOperationOutcomeException(new UnprocessableEntityException(theException.getMessage()), SystemCode.INVALID_PARAMETER, IssueType.INVALID);
}
if (theException instanceof MethodNotAllowedException && theException.getMessage().contains("request must use HTTP GET")) {
return OperationOutcomeFactory.buildOperationOutcomeException(new UnprocessableEntityException(theException.getMessage()), SystemCode.BAD_REQUEST, IssueType.INVALID);
}
if (theException instanceof InvalidRequestException && theException.getMessage().startsWith("Failed to parse request body as JSON resource. Error was: ")) {
// #250 422 INVALID_RESOURCE not 400 BAD_REQUEST
return OperationOutcomeFactory.buildOperationOutcomeException(new UnprocessableEntityException(theException.getMessage()), SystemCode.INVALID_RESOURCE, IssueType.INVALID);
}
if (theException instanceof InvalidRequestException && theException.getMessage().startsWith("Invalid request: ")) {
return OperationOutcomeFactory.buildOperationOutcomeException(new InvalidRequestException(theException.getMessage()), SystemCode.BAD_REQUEST, IssueType.INVALID);
}
if (theException instanceof InvalidRequestException && theException.getMessage().contains("non-repeatable parameter")) {
return OperationOutcomeFactory.buildOperationOutcomeException(new InvalidRequestException(theException.getMessage()), SystemCode.BAD_REQUEST, IssueType.INVALID);
}
if (theException instanceof InvalidRequestException && theException.getMessage().contains("header blank")) {
return OperationOutcomeFactory.buildOperationOutcomeException(new InvalidRequestException(theException.getMessage()), SystemCode.BAD_REQUEST, IssueType.INVALID);
}
if (theException instanceof InvalidRequestException && theException.getMessage().contains("InvalidResourceType")) {
return OperationOutcomeFactory.buildOperationOutcomeException(new UnprocessableEntityException(theException.getMessage()), SystemCode.INVALID_RESOURCE, IssueType.INVALID);
}
if (theException instanceof InvalidRequestException && theException.getMessage().contains("Can not create resource with ID")) {
return OperationOutcomeFactory.buildOperationOutcomeException(new UnprocessableEntityException(theException.getMessage()), SystemCode.BAD_REQUEST, IssueType.INVALID);
}
if (theException instanceof ResourceNotFoundException && theException.getMessage().contains("Unknown resource type")) {
return OperationOutcomeFactory.buildOperationOutcomeException((ResourceNotFoundException) theException, SystemCode.BAD_REQUEST, IssueType.INVALID);
}
// }
if (theException instanceof ResourceVersionConflictException && theException.getMessage().contains("Slot is already in use.")) {
ResourceVersionConflictException exception = (ResourceVersionConflictException) theException;
return OperationOutcomeFactory.buildOperationOutcomeException(exception, SystemCode.DUPLICATE_REJECTED, IssueType.CONFLICT);
}
if (theException instanceof ResourceVersionConflictException) {
ResourceVersionConflictException exception = (ResourceVersionConflictException) theException;
return OperationOutcomeFactory.buildOperationOutcomeException(exception, SystemCode.FHIR_CONSTRAINT_VIOLATION, IssueType.CONFLICT);
}
if (theException instanceof BaseServerResponseException) {
BaseServerResponseException baseServerResponseException = (BaseServerResponseException) theException;
// If the OperationalOutcome is already set, just return it.
return null == baseServerResponseException.getOperationOutcome() ? OperationOutcomeFactory.buildOperationOutcomeException(baseServerResponseException, SystemCode.BAD_REQUEST, IssueType.INVALID) : baseServerResponseException;
}
// Default catch all.
return OperationOutcomeFactory.buildOperationOutcomeException(new InvalidRequestException(theException.getMessage()), SystemCode.BAD_REQUEST, IssueType.INVALID);
}
use of ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException in project gpconnect-demonstrator by nhsconnect.
the class LocationResourceProvider method getLocationById.
@Read(version = true)
public Location getLocationById(@IdParam IdType locationId) {
LocationDetails locationDetails = locationSearch.findLocationById(locationId.getIdPart());
if (locationDetails == null) {
throw OperationOutcomeFactory.buildOperationOutcomeException(new ResourceNotFoundException("No location details found for location ID: " + locationId.getIdPart()), SystemCode.REFERENCE_NOT_FOUND, IssueType.INCOMPLETE);
}
Location location = locationDetailsToLocation(locationDetails);
return location;
}
Aggregations