use of utils.BusinessException in project jdchain-core by blockchain-jd-com.
the class ManagementController method getConsensusNodeState.
@RequestMapping(path = "/monitor/consensus/nodestate/{ledgerHash}", method = RequestMethod.GET)
public NodeState getConsensusNodeState(@PathVariable("ledgerHash") String base58LedgerHash) {
byte[] ledgerHashBytes;
try {
ledgerHashBytes = Base58Utils.decode(base58LedgerHash);
} catch (Exception e) {
String errMsg = "Error occurred while resolving the base58 ledger hash string[" + base58LedgerHash + "]! --" + e.getMessage();
LOGGER.error(errMsg, e);
throw new BusinessException(errMsg);
}
HashDigest ledgerHash;
try {
ledgerHash = Crypto.resolveAsHashDigest(ledgerHashBytes);
} catch (Exception e) {
String errMsg = "Error occurred while resolving the ledger hash[" + base58LedgerHash + "]! --" + e.getMessage();
LOGGER.error(errMsg, e);
throw new BusinessException(errMsg);
}
NodeServer nodeServer = ledgerPeers.get(ledgerHash);
if (nodeServer == null) {
throw new BusinessException("The consensus node of ledger[" + base58LedgerHash + "] don't exist!");
}
try {
// String stateInfo = JSONSerializeUtils.serializeToJSON(nodeServer.getState(), true);
return nodeServer.getState();
} catch (Exception e) {
String errMsg = "Error occurred while detecting the state info of the current consensus node in ledger[" + base58LedgerHash + "]! --" + e.getMessage();
LOGGER.error(errMsg, e);
throw new BusinessException(errMsg);
}
}
use of utils.BusinessException 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 utils.BusinessException 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