Configure default exception handlers for REST services.

This commit is contained in:
Paulo Gustavo Veiga
2012-02-21 20:04:17 -03:00
parent 7e59b19fc0
commit f96b0d49c2
4 changed files with 43 additions and 12 deletions

View File

@@ -0,0 +1,27 @@
package com.wisemapping.rest;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
public class BaseController {
@ExceptionHandler(IllegalArgumentException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ResponseBody
public String handleClientErrors(Exception ex) {
ex.printStackTrace();
return ex.getMessage();
}
@ExceptionHandler(Exception.class)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
@ResponseBody
public String handleServerErrors(Exception ex) {
ex.printStackTrace();
// LOGGER.error(ex.getMessage(), ex);
return ex.getMessage();
}
}