dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #25878
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 12851: more exception handling in fred-api
------------------------------------------------------------
revno: 12851
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2013-11-01 12:24:53 +0100
message:
more exception handling in fred-api
modified:
dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/controller/FacilityAdvice.java
dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/domain/Facility.java
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/controller/FacilityAdvice.java'
--- dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/controller/FacilityAdvice.java 2013-11-01 10:15:04 +0000
+++ dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/controller/FacilityAdvice.java 2013-11-01 11:24:53 +0000
@@ -37,19 +37,30 @@
import org.hisp.dhis.web.webapi.v1.exception.FacilityNotFoundException;
import org.hisp.dhis.web.webapi.v1.exception.UuidFormatException;
import org.hisp.dhis.web.webapi.v1.utils.MessageUtils;
+import org.springframework.beans.ConversionNotSupportedException;
+import org.springframework.beans.TypeMismatchException;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
+import org.springframework.http.converter.HttpMessageNotReadableException;
+import org.springframework.http.converter.HttpMessageNotWritableException;
+import org.springframework.validation.BindException;
import org.springframework.web.HttpMediaTypeNotAcceptableException;
import org.springframework.web.HttpMediaTypeNotSupportedException;
+import org.springframework.web.HttpRequestMethodNotSupportedException;
+import org.springframework.web.bind.MethodArgumentNotValidException;
+import org.springframework.web.bind.MissingServletRequestParameterException;
+import org.springframework.web.bind.ServletRequestBindingException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.HttpServerErrorException;
import org.springframework.web.client.HttpStatusCodeException;
import org.springframework.web.context.request.WebRequest;
+import org.springframework.web.multipart.support.MissingServletRequestPartException;
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;
+import org.springframework.web.servlet.mvc.multiaction.NoSuchRequestHandlingMethodException;
import java.io.IOException;
@@ -130,4 +141,112 @@
return new ResponseEntity<Object>( MessageUtils.jsonMessage(
Integer.toString( status.value() ), ex.getMessage() ), status );
}
+
+ @Override
+ protected ResponseEntity<Object> handleExceptionInternal( Exception ex, Object body, HttpHeaders headers, HttpStatus status, WebRequest request )
+ {
+ headers.add( "Content-Type", MediaType.APPLICATION_JSON_VALUE );
+
+ return new ResponseEntity<Object>( MessageUtils.jsonMessage(
+ Integer.toString( status.value() ), ex.getMessage() ), status );
+ }
+
+ @Override
+ protected ResponseEntity<Object> handleNoSuchRequestHandlingMethod( NoSuchRequestHandlingMethodException ex, HttpHeaders headers, HttpStatus status, WebRequest request )
+ {
+ headers.add( "Content-Type", MediaType.APPLICATION_JSON_VALUE );
+
+ return new ResponseEntity<Object>( MessageUtils.jsonMessage(
+ Integer.toString( status.value() ), ex.getMessage() ), status );
+ }
+
+ @Override
+ protected ResponseEntity<Object> handleHttpRequestMethodNotSupported( HttpRequestMethodNotSupportedException ex, HttpHeaders headers, HttpStatus status, WebRequest request )
+ {
+ headers.add( "Content-Type", MediaType.APPLICATION_JSON_VALUE );
+
+ return new ResponseEntity<Object>( MessageUtils.jsonMessage(
+ Integer.toString( status.value() ), ex.getMessage() ), status );
+ }
+
+ @Override
+ protected ResponseEntity<Object> handleMissingServletRequestParameter( MissingServletRequestParameterException ex, HttpHeaders headers, HttpStatus status, WebRequest request )
+ {
+ headers.add( "Content-Type", MediaType.APPLICATION_JSON_VALUE );
+
+ return new ResponseEntity<Object>( MessageUtils.jsonMessage(
+ Integer.toString( status.value() ), ex.getMessage() ), status );
+ }
+
+ @Override
+ protected ResponseEntity<Object> handleServletRequestBindingException( ServletRequestBindingException ex, HttpHeaders headers, HttpStatus status, WebRequest request )
+ {
+ headers.add( "Content-Type", MediaType.APPLICATION_JSON_VALUE );
+
+ return new ResponseEntity<Object>( MessageUtils.jsonMessage(
+ Integer.toString( status.value() ), ex.getMessage() ), status );
+ }
+
+ @Override
+ protected ResponseEntity<Object> handleConversionNotSupported( ConversionNotSupportedException ex, HttpHeaders headers, HttpStatus status, WebRequest request )
+ {
+ headers.add( "Content-Type", MediaType.APPLICATION_JSON_VALUE );
+
+ return new ResponseEntity<Object>( MessageUtils.jsonMessage(
+ Integer.toString( status.value() ), ex.getMessage() ), status );
+ }
+
+ @Override
+ protected ResponseEntity<Object> handleTypeMismatch( TypeMismatchException ex, HttpHeaders headers, HttpStatus status, WebRequest request )
+ {
+ headers.add( "Content-Type", MediaType.APPLICATION_JSON_VALUE );
+
+ return new ResponseEntity<Object>( MessageUtils.jsonMessage(
+ Integer.toString( status.value() ), ex.getMessage() ), status );
+ }
+
+ @Override
+ protected ResponseEntity<Object> handleHttpMessageNotReadable( HttpMessageNotReadableException ex, HttpHeaders headers, HttpStatus status, WebRequest request )
+ {
+ headers.add( "Content-Type", MediaType.APPLICATION_JSON_VALUE );
+
+ return new ResponseEntity<Object>( MessageUtils.jsonMessage(
+ Integer.toString( status.value() ), ex.getMessage() ), status );
+ }
+
+ @Override
+ protected ResponseEntity<Object> handleHttpMessageNotWritable( HttpMessageNotWritableException ex, HttpHeaders headers, HttpStatus status, WebRequest request )
+ {
+ headers.add( "Content-Type", MediaType.APPLICATION_JSON_VALUE );
+
+ return new ResponseEntity<Object>( MessageUtils.jsonMessage(
+ Integer.toString( status.value() ), ex.getMessage() ), status );
+ }
+
+ @Override
+ protected ResponseEntity<Object> handleMethodArgumentNotValid( MethodArgumentNotValidException ex, HttpHeaders headers, HttpStatus status, WebRequest request )
+ {
+ headers.add( "Content-Type", MediaType.APPLICATION_JSON_VALUE );
+
+ return new ResponseEntity<Object>( MessageUtils.jsonMessage(
+ Integer.toString( status.value() ), ex.getMessage() ), status );
+ }
+
+ @Override
+ protected ResponseEntity<Object> handleMissingServletRequestPart( MissingServletRequestPartException ex, HttpHeaders headers, HttpStatus status, WebRequest request )
+ {
+ headers.add( "Content-Type", MediaType.APPLICATION_JSON_VALUE );
+
+ return new ResponseEntity<Object>( MessageUtils.jsonMessage(
+ Integer.toString( status.value() ), ex.getMessage() ), status );
+ }
+
+ @Override
+ protected ResponseEntity<Object> handleBindException( BindException ex, HttpHeaders headers, HttpStatus status, WebRequest request )
+ {
+ headers.add( "Content-Type", MediaType.APPLICATION_JSON_VALUE );
+
+ return new ResponseEntity<Object>( MessageUtils.jsonMessage(
+ Integer.toString( status.value() ), ex.getMessage() ), status );
+ }
}
=== modified file 'dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/domain/Facility.java'
--- dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/domain/Facility.java 2013-08-23 16:05:01 +0000
+++ dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/domain/Facility.java 2013-11-01 11:24:53 +0000
@@ -53,7 +53,7 @@
// Name of the facility
@NotNull
- @Length(min = 2, max = 160)
+ @Length( min = 2, max = 160 )
private String name;
// Active = true/false indicates whether the facility is active or not