use of com.jd.httpservice.utils.web.WebResponse.ErrorMessage in project jdchain-core by blockchain-jd-com.
the class GatewayGlobalExceptionHandler method json.
@ExceptionHandler(value = Exception.class)
@ResponseBody
public WebResponse json(HttpServletRequest req, Exception ex) {
ErrorMessage message = null;
String reqURL = "[" + req.getMethod() + "] " + req.getRequestURL().toString();
if (ex instanceof BusinessException) {
logger.error("BusinessException occurred! --[RequestURL=" + reqURL + "][" + ex.getClass().toString() + "] " + ex.getMessage(), ex);
BusinessException businessException = (BusinessException) ex;
message = new ErrorMessage(businessException.getErrorCode(), businessException.getMessage());
} else {
logger.error("Unexpected exception occurred! --[RequestURL=" + reqURL + "][" + ex.getClass().toString() + "]" + ex.getMessage(), ex);
message = new ErrorMessage(ErrorCode.UNEXPECTED.getValue(), ErrorCode.UNEXPECTED.getDescription(ex.getMessage()));
}
WebResponse response = WebResponse.createFailureResult(message);
return response;
}
use of com.jd.httpservice.utils.web.WebResponse.ErrorMessage in project jdchain-core by blockchain-jd-com.
the class PeerGlobalExceptionHandler method json.
@ExceptionHandler(value = Exception.class)
@ResponseBody
public WebResponse json(HttpServletRequest req, Exception ex) {
String reqURL = req.getRequestURL().insert(0, "[" + req.getMethod() + "] ").toString();
ErrorMessage message = null;
if (ex instanceof BusinessException) {
logger.error("BusinessException occurred! --[RequestURL=" + reqURL + "][" + ex.getClass().toString() + "] " + ex.getMessage(), ex);
BusinessException businessException = (BusinessException) ex;
message = new ErrorMessage(businessException.getErrorCode(), businessException.getMessage());
} else if (ex instanceof JSONException) {
logger.error("JSONException occurred! --[RequestURL=" + reqURL + "][" + ex.getClass().toString() + "] " + ex.getMessage(), ex);
message = new ErrorMessage(ErrorCode.REQUEST_PARAM_FORMAT_ILLEGAL.getValue(), ErrorCode.REQUEST_PARAM_FORMAT_ILLEGAL.getDescription());
} else {
logger.error("Unexpected exception occurred! --[RequestURL=" + reqURL + "][" + ex.getClass().toString() + "]" + ex.getMessage(), ex);
message = new ErrorMessage(ErrorCode.UNEXPECTED.getValue(), ErrorCode.UNEXPECTED.getDescription(ex.getMessage()));
}
WebResponse responseResult = WebResponse.createFailureResult(message);
return responseResult;
}
Aggregations