Search in sources :

Example 1 with ErrorData

use of io.nuls.kernel.model.ErrorData in project nuls by nuls-io.

the class RpcServerFilter method toResponse.

@Override
public Response toResponse(Exception e) {
    // System.out.println("---------------" + request.getRequestURI());
    Log.error("RequestURI is " + request.getRequestURI(), e);
    RpcClientResult result;
    if (e instanceof NulsException) {
        NulsException exception = (NulsException) e;
        result = new RpcClientResult(false, exception.getErrorCode());
    } else if (e instanceof NulsRuntimeException) {
        NulsRuntimeException exception = (NulsRuntimeException) e;
        result = new RpcClientResult(false, new ErrorData(exception.getCode(), exception.getMessage()));
    } else {
        result = Result.getFailed().setMsg(e.getMessage()).toRpcClientResult();
    }
    return Response.ok(result, MediaType.APPLICATION_JSON).build();
}
Also used : RpcClientResult(io.nuls.kernel.model.RpcClientResult) NulsException(io.nuls.kernel.exception.NulsException) NulsRuntimeException(io.nuls.kernel.exception.NulsRuntimeException) ErrorData(io.nuls.kernel.model.ErrorData)

Aggregations

NulsException (io.nuls.kernel.exception.NulsException)1 NulsRuntimeException (io.nuls.kernel.exception.NulsRuntimeException)1 ErrorData (io.nuls.kernel.model.ErrorData)1 RpcClientResult (io.nuls.kernel.model.RpcClientResult)1