/** * Construct an exception with a default message that includes the provided service definition ID. * * @param serviceDefinitionId the ID of the service definition */ public ServiceDefinitionDoesNotExistException(String serviceDefinitionId) { super(buildMessage(serviceDefinitionId)); }
protected ServiceDefinition getRequiredServiceDefinition(String serviceDefinitionId) { ServiceDefinition serviceDefinition = getServiceDefinition(serviceDefinitionId); if (serviceDefinition == null) { throw new ServiceDefinitionDoesNotExistException(serviceDefinitionId); } return serviceDefinition; }
@ExceptionHandler(ServiceDefinitionDoesNotExistException.class) public ResponseEntity<ErrorMessage> handleException(ServiceDefinitionDoesNotExistException ex) { log.debug("Service definition does not exist: ", ex); return getErrorResponse(ex.getMessage(), HttpStatus.UNPROCESSABLE_ENTITY); }
protected ServiceDefinition getRequiredServiceDefinition(String serviceDefinitionId) { ServiceDefinition serviceDefinition = getServiceDefinition(serviceDefinitionId); if (serviceDefinition == null) { throw new ServiceDefinitionDoesNotExistException(serviceDefinitionId); } return serviceDefinition; }
protected Mono<ServiceDefinition> getRequiredServiceDefinition(String serviceDefinitionId) { return getServiceDefinition(serviceDefinitionId) .switchIfEmpty(Mono.error(new ServiceDefinitionDoesNotExistException(serviceDefinitionId))); }
/** * Construct an exception with an error code and default message that includes the * provided service definition ID. * * @param errorCode a single word in camel case that uniquely identifies the error condition * @param serviceDefinitionId the ID of the service definition */ public ServiceDefinitionDoesNotExistException(String errorCode, String serviceDefinitionId) { super(errorCode, buildMessage(serviceDefinitionId)); }
@Test public void serviceDefinitionDoesNotExistException() { ServiceDefinitionDoesNotExistException exception = new ServiceDefinitionDoesNotExistException("service-definition-id"); ErrorMessage errorMessage = exceptionHandler.handleException(exception); assertThat(errorMessage.getError()).isNull(); assertThat(errorMessage.getMessage()).contains("id=service-definition-id"); }
/** * Construct an exception with an error code and default message that includes the * provided service definition ID. * * @param errorCode a single word in camel case that uniquely identifies the error condition * @param serviceDefinitionId the ID of the service definition */ public ServiceDefinitionDoesNotExistException(String errorCode, String serviceDefinitionId) { super(errorCode, buildMessage(serviceDefinitionId)); }
/** * Construct an exception with a default message that includes the provided service definition ID. * * @param serviceDefinitionId the ID of the service definition */ public ServiceDefinitionDoesNotExistException(String serviceDefinitionId) { super(buildMessage(serviceDefinitionId)); }