1919
2020import org .apache .logging .log4j .Logger ;
2121import org .springframework .http .HttpStatus ;
22+ import org .springframework .http .ResponseEntity ;
2223import org .springframework .security .access .AccessDeniedException ;
2324import org .springframework .web .HttpRequestMethodNotSupportedException ;
2425import org .springframework .web .bind .annotation .ControllerAdvice ;
@@ -65,8 +66,8 @@ protected String getRestApiVersion() {
6566 @ ExceptionHandler ({RegionNotFoundException .class , ResourceNotFoundException .class })
6667 @ ResponseBody
6768 @ ResponseStatus (HttpStatus .NOT_FOUND )
68- public String handle (final RuntimeException e ) {
69- return convertErrorAsJson (e .getMessage ());
69+ public ResponseEntity < String > handle (final RuntimeException e ) {
70+ return convertErrorAsJson (HttpStatus . NOT_FOUND , e .getMessage ());
7071 }
7172
7273 /**
@@ -80,8 +81,8 @@ public String handle(final RuntimeException e) {
8081 @ ExceptionHandler ({MalformedJsonException .class })
8182 @ ResponseBody
8283 @ ResponseStatus (HttpStatus .BAD_REQUEST )
83- public String handleException (final RuntimeException e ) {
84- return convertErrorAsJson (e .getMessage ());
84+ public ResponseEntity < String > handleException (final RuntimeException e ) {
85+ return convertErrorAsJson (HttpStatus . BAD_REQUEST , e .getMessage ());
8586 }
8687
8788 /**
@@ -95,8 +96,8 @@ public String handleException(final RuntimeException e) {
9596 @ ExceptionHandler (GemfireRestException .class )
9697 @ ResponseBody
9798 @ ResponseStatus (HttpStatus .INTERNAL_SERVER_ERROR )
98- public String handleException (final GemfireRestException ge ) {
99- return convertErrorAsJson (ge );
99+ public ResponseEntity < String > handleException (final GemfireRestException ge ) {
100+ return convertErrorAsJson (HttpStatus . INTERNAL_SERVER_ERROR , ge );
100101 }
101102
102103 /**
@@ -111,8 +112,8 @@ public String handleException(final GemfireRestException ge) {
111112 @ ExceptionHandler (DataTypeNotSupportedException .class )
112113 @ ResponseBody
113114 @ ResponseStatus (HttpStatus .NOT_ACCEPTABLE )
114- public String handleException (final DataTypeNotSupportedException tns ) {
115- return convertErrorAsJson (tns .getMessage ());
115+ public ResponseEntity < String > handleException (final DataTypeNotSupportedException tns ) {
116+ return convertErrorAsJson (HttpStatus . NOT_ACCEPTABLE , tns .getMessage ());
116117 }
117118
118119 /**
@@ -127,8 +128,8 @@ public String handleException(final DataTypeNotSupportedException tns) {
127128 @ ExceptionHandler (HttpRequestMethodNotSupportedException .class )
128129 @ ResponseBody
129130 @ ResponseStatus (HttpStatus .METHOD_NOT_ALLOWED )
130- public String handleException (final HttpRequestMethodNotSupportedException e ) {
131- return convertErrorAsJson (e .getMessage ());
131+ public ResponseEntity < String > handleException (final HttpRequestMethodNotSupportedException e ) {
132+ return convertErrorAsJson (HttpStatus . METHOD_NOT_ALLOWED , e .getMessage ());
132133 }
133134
134135 /**
@@ -142,8 +143,8 @@ public String handleException(final HttpRequestMethodNotSupportedException e) {
142143 @ ExceptionHandler (AccessDeniedException .class )
143144 @ ResponseBody
144145 @ ResponseStatus (HttpStatus .FORBIDDEN )
145- public String handleException (final AccessDeniedException cause ) {
146- return convertErrorAsJson (cause .getMessage ());
146+ public ResponseEntity < String > handleException (final AccessDeniedException cause ) {
147+ return convertErrorAsJson (HttpStatus . FORBIDDEN , cause .getMessage ());
147148 }
148149
149150 /**
@@ -156,8 +157,8 @@ public String handleException(final AccessDeniedException cause) {
156157 @ ExceptionHandler (NotAuthorizedException .class )
157158 @ ResponseBody
158159 @ ResponseStatus (HttpStatus .FORBIDDEN )
159- public String handleException (final NotAuthorizedException cause ) {
160- return convertErrorAsJson (cause .getMessage ());
160+ public ResponseEntity < String > handleException (final NotAuthorizedException cause ) {
161+ return convertErrorAsJson (HttpStatus . FORBIDDEN , cause .getMessage ());
161162 }
162163
163164 /**
@@ -170,8 +171,8 @@ public String handleException(final NotAuthorizedException cause) {
170171 @ ExceptionHandler (EntityNotFoundException .class )
171172 @ ResponseBody
172173 @ ResponseStatus (HttpStatus .NOT_FOUND )
173- public String handleException (final EntityNotFoundException cause ) {
174- return convertErrorAsJson (cause .getMessage ());
174+ public ResponseEntity < String > handleException (final EntityNotFoundException cause ) {
175+ return convertErrorAsJson (HttpStatus . NOT_FOUND , cause .getMessage ());
175176 }
176177
177178 /**
@@ -185,7 +186,7 @@ public String handleException(final EntityNotFoundException cause) {
185186 @ ExceptionHandler (Throwable .class )
186187 @ ResponseBody
187188 @ ResponseStatus (HttpStatus .INTERNAL_SERVER_ERROR )
188- public String handleException (final Throwable cause ) {
189+ public ResponseEntity < String > handleException (final Throwable cause ) {
189190 final StringWriter stackTraceWriter = new StringWriter ();
190191 cause .printStackTrace (new PrintWriter (stackTraceWriter ));
191192 final String stackTrace = stackTraceWriter .toString ();
@@ -194,7 +195,7 @@ public String handleException(final Throwable cause) {
194195 logger .debug (stackTrace );
195196 }
196197
197- return convertErrorAsJson (cause .getMessage ());
198+ return convertErrorAsJson (HttpStatus . INTERNAL_SERVER_ERROR , cause .getMessage ());
198199 }
199200
200201}
0 commit comments