Add service broker bad request exception
This commit is contained in:
@@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.cloud.servicebroker.exception.ServiceBrokerApiVersionException;
|
||||
import org.springframework.cloud.servicebroker.exception.ServiceBrokerAsyncRequiredException;
|
||||
import org.springframework.cloud.servicebroker.exception.ServiceBrokerBadRequestException;
|
||||
import org.springframework.cloud.servicebroker.exception.ServiceBrokerInvalidParametersException;
|
||||
import org.springframework.cloud.servicebroker.exception.ServiceDefinitionDoesNotExistException;
|
||||
import org.springframework.cloud.servicebroker.exception.ServiceInstanceDoesNotExistException;
|
||||
@@ -141,6 +142,12 @@ public class BaseController {
|
||||
return getErrorResponse(ex.getMessage(), HttpStatus.UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
@ExceptionHandler(ServiceBrokerBadRequestException.class)
|
||||
public ResponseEntity<ErrorMessage> handleException(ServiceBrokerBadRequestException ex) {
|
||||
log.debug("Invalid request received: ", ex);
|
||||
return getErrorResponse(ex.getMessage(), HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
@ExceptionHandler(Exception.class)
|
||||
public ResponseEntity<ErrorMessage> handleException(Exception ex) {
|
||||
log.debug("Unknown exception handled: ", ex);
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package org.springframework.cloud.servicebroker.exception;
|
||||
|
||||
/**
|
||||
* Thrown to indicate that request is invalid. 400 response code should be returned.
|
||||
*/
|
||||
public class ServiceBrokerBadRequestException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = 4719676639792071582L;
|
||||
|
||||
public ServiceBrokerBadRequestException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public ServiceBrokerBadRequestException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public ServiceBrokerBadRequestException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -18,6 +18,7 @@ import org.junit.runner.RunWith;
|
||||
import org.mockito.*;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.springframework.cloud.servicebroker.exception.ServiceBrokerAsyncRequiredException;
|
||||
import org.springframework.cloud.servicebroker.exception.ServiceBrokerBadRequestException;
|
||||
import org.springframework.cloud.servicebroker.exception.ServiceBrokerInvalidParametersException;
|
||||
import org.springframework.cloud.servicebroker.exception.ServiceInstanceDoesNotExistException;
|
||||
import org.springframework.cloud.servicebroker.exception.ServiceInstanceExistsException;
|
||||
@@ -249,6 +250,22 @@ public class ServiceInstanceControllerIntegrationTest extends ControllerIntegrat
|
||||
.andExpect(jsonPath("$.description", is("invalid parameters description")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createServiceInstanceWithBadRequestFails() throws Exception {
|
||||
when(serviceInstanceService.createServiceInstance(eq(syncCreateRequest)))
|
||||
.thenThrow(new ServiceBrokerBadRequestException("invalid request description"));
|
||||
|
||||
setupCatalogService(syncCreateRequest.getServiceDefinitionId());
|
||||
|
||||
mockMvc.perform(put(buildUrl(syncCreateRequest, false))
|
||||
.content(DataFixture.toJson(syncCreateRequest))
|
||||
.header(API_INFO_LOCATION_HEADER, API_INFO_LOCATION)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.accept(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(jsonPath("$.description", is("invalid request description")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createServiceInstanceWithInvalidFieldsFails() throws Exception {
|
||||
when(serviceInstanceService.createServiceInstance(eq(syncCreateRequest)))
|
||||
|
||||
Reference in New Issue
Block a user