Search in sources :

Example 1 with BusinessException

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);
    }
}
Also used : BusinessException(utils.BusinessException) BusinessException(utils.BusinessException)

Example 2 with BusinessException

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;
}
Also used : BusinessException(utils.BusinessException) WebResponse(com.jd.httpservice.utils.web.WebResponse) ErrorMessage(com.jd.httpservice.utils.web.WebResponse.ErrorMessage) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 3 with BusinessException

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;
}
Also used : BusinessException(utils.BusinessException) WebResponse(com.jd.httpservice.utils.web.WebResponse) JSONException(com.alibaba.fastjson.JSONException) ErrorMessage(com.jd.httpservice.utils.web.WebResponse.ErrorMessage) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

BusinessException (utils.BusinessException)3 WebResponse (com.jd.httpservice.utils.web.WebResponse)2 ErrorMessage (com.jd.httpservice.utils.web.WebResponse.ErrorMessage)2 ExceptionHandler (org.springframework.web.bind.annotation.ExceptionHandler)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2 JSONException (com.alibaba.fastjson.JSONException)1