using System; namespace EdjCase.JsonRpc.Core { /// /// Rpc server exception that contains Rpc specfic error info /// public class RpcException : Exception { /// /// Rpc error code that corresponds to the documented integer codes /// public int ErrorCode { get; } /// /// Custom data attached to the error if needed /// public object RpcData { get; } /// Rpc error code /// Error message /// Custom data if needed for error response /// Inner exception (optional) public RpcException(int errorCode, string message, Exception innerException = null, object data = null) : base(message, innerException) { this.ErrorCode = errorCode; this.RpcData = data; } /// Rpc error code /// Error message /// Custom data if needed for error response /// Inner exception (optional) public RpcException(RpcErrorCode errorCode, string message, Exception innerException = null, object data = null) : this((int)errorCode, message, innerException, data) { } public RpcError ToRpcError(bool includeServerErrors) { string message = this.Message; if (includeServerErrors) { message += Environment.NewLine + "Exception: " + this.InnerException; } return new RpcError(this.ErrorCode, this.Message, this.RpcData); } } }