Spring @ControllerAdvice vs ErrorController -
in rest serving app, i'm planning create @controlleradvice class catch controller thrown exceptions , return responseentity objects according error type.
but i've set @restcontroller extending errorcontroller catch "whitelabel" errors.
does 2 interfers in manner ? in cases errorcontroller called when @controlleradvice set ?
edit errorcontroller code requested
@restcontroller public class controllercustomerror implements errorcontroller{ //error json object public class errorjson { public integer status; public string error; public string message; public string timestamp; public string trace; public errorjson(int status, map<string, object> errorattributes) { this.status = status; this.error = (string) errorattributes.get("error"); this.message = (string) errorattributes.get("message"); this.timestamp = errorattributes.get("timestamp").tostring(); this.trace = (string) errorattributes.get("trace"); } } private static final string path = "/error"; @value("${hybus.error.stacktrace.include}") private boolean includestacktrace = false; @autowired private errorattributes errorattributes; @requestmapping(value = path) errorjson error(httpservletrequest request, httpservletresponse response) { // appropriate http response code (e.g. 404 or 500) automatically set spring. // here define response body. return new errorjson(response.getstatus(), geterrorattributes(request, includestacktrace)); } @override public string geterrorpath() { return path; } private map<string, object> geterrorattributes(httpservletrequest request, boolean includestacktrace) { requestattributes requestattributes = new servletrequestattributes(request); return errorattributes.geterrorattributes(requestattributes, includestacktrace); } }
Comments
Post a Comment