private void HandleInvalidShare(IShare share) { var miner = (IStratumMiner)share.Miner; if (miner.Username.Equals(share.PayoutUser) && share.Error != ShareError.InsideSleepWindow) { miner.InvalidShareCount++; } JsonRpcException exception = null; // the exception determined by the stratum error code. switch (share.Error) { case ShareError.DuplicateShare: exception = new DuplicateShareError(share.Nonce); break; case ShareError.IncorrectExtraNonce2Size: exception = new OtherError("Incorrect extranonce2 size"); break; case ShareError.IncorrectNTimeSize: exception = new OtherError("Incorrect nTime size"); break; case ShareError.IncorrectNonceSize: exception = new OtherError("Incorrect nonce size"); break; case ShareError.JobNotFound: exception = new JobNotFoundError(share.JobId); break; case ShareError.LowDifficultyShare: exception = new LowDifficultyShare(share.Difficulty); break; case ShareError.NTimeOutOfRange: exception = new OtherError("nTime out of range"); break; case ShareError.InsideSleepWindow: exception = new OtherError("Inside Sleep Window"); break; } JsonRpcContext.SetException(exception); // set the stratum exception within the json-rpc reply. Debug.Assert(exception != null); // exception should be never null when the share is marked as invalid. if (share.Error == ShareError.InsideSleepWindow) { if (DateTime.Now.Millisecond % 1000 == 0) { _logger.Debug("Rejected share by miner {0:l}, reason: {1:l}", share.PayoutUser, exception.message); } } else { _logger.Debug("Rejected share by miner {0:l}, reason: {1:l}", share.PayoutUser, exception.message); } }
private JsonRpcException OnJsonRpcException(JsonRpcRequestContext rpc, JsonRpcException ex) { // Serivce Call Service 业务异常透传 if (ex.data is JsonRpcException && ((JsonRpcException)ex.data).code == 32000) { ex.code = 32000; ex.message = ((JsonRpcException)ex.data).message; ex.data = null; return(ex); } // Service内部产生的异常是BusinessException时,需要抛给调用端,并且指定RPC错误编码为:32000,没有堆栈。 // 自定义代码,抛出业务异常 if (ex.data.GetType().Name == "BusinessException") { ex.code = 32000; ex.message = ((Exception)ex.data).Message; ex.data = null; } else if (ex.data is ValidationException) { ex.code = 32000; ex.message = ((ValidationException)ex.data).Message; ex.data = null; } else { if (ex.data != null) { ex.data = ex.data.ToString(); } } return(ex); }
/// <summary> /// Handles possible authentication exceptions /// </summary> private void HandleAuthenticationExceptions(object param) { Exception exception = param as Exception; if (exception != null) { JsonRpcException rpcException = exception as JsonRpcException; if (rpcException != null) { // if the exception comes from rpc, we have two special situations to handle: // 1 short code was wrong (might happen a lot) // 2 security token was wrong (should never happen) // in both cases, we need to request new security token if ((rpcException.TypeName == "codeOrchestra.colt.core.rpc.security.InvalidShortCodeException") || (rpcException.TypeName == "codeOrchestra.colt.core.rpc.security.InvalidAuthTokenException")) { settingObject.SecurityToken = null; // request new security token immediately GetSecurityToken(); } } else { TraceManager.Add(exception.ToString(), -1); } } }
public static void LogRpcException(this Logger logger, JsonRpcException e) { switch (e.Code) { case (int)ProtocolErrorCode.Error: logger.Error("An unknown error occured with the TLC-FI. See trace for exception details."); logger.Trace(e, "An unknown error occured with the TLC-FI:"); break; case (int)ProtocolErrorCode.NotAuthorized: logger.Error("Client is not authorized to use the server. See trace for exception details."); logger.Trace(e, "Client is not authorized to use the server:"); break; case (int)ProtocolErrorCode.NoRights: logger.Error("Client has no (appropriate) rights on the server. See trace for exception details."); logger.Trace(e, "Client has no (appropriate) rights on the server:"); break; case (int)ProtocolErrorCode.InvalidProtocol: logger.Error("The protocol version used by the client is not compatible with that at the server. See trace for exception details."); logger.Trace(e, "The protocol version used by the client is not compatible with that at the server:"); break; case (int)ProtocolErrorCode.AlreadyRegistered: logger.Error("Client is already registered. See trace for exception details."); logger.Trace(e, "Client is already registered:"); break; case (int)ProtocolErrorCode.UnknownObjectType: logger.Error("Unknown object type. See trace for exception details."); logger.Trace(e, "Unknown object type:"); break; case (int)ProtocolErrorCode.MissingAttribute: logger.Error("Missing attribute. See trace for exception details."); logger.Trace(e, "Missing attribute:"); break; case (int)ProtocolErrorCode.InvalidAttributeType: logger.Error("Invalid attribute type. See trace for exception details."); logger.Trace(e, "Invalid attribute type:"); break; case (int)ProtocolErrorCode.InvalidAttributeValue: logger.Error("Invalid attribute value. See trace for exception details."); logger.Trace(e, "Invalid attribute value:"); break; case (int)ProtocolErrorCode.InvalidObjectReference: logger.Error("Invalid object reference. See trace for exception details."); logger.Trace(e, "Invalid object reference:"); break; default: logger.Error("Unknown type of error ({0} is not a valid value for enum ProtocolErrorCode). See trace for exception details.", e.Code); logger.Trace(e, "Unknown type of error ({0} is not a valid value for enum ProtocolErrorCode):", e.Code); break; } }
public void TestGetJsonWithoutData() { JsonRpcException exception = new JsonRpcException(42, "msg"); JObject json = exception.GetJson(); Assert.AreEqual(42, (int)json["code"]); Assert.AreEqual("msg", (string)json["message"]); Assert.IsNull(json["data"]); }
public static Message CreateErrorMessage(MessageVersion messageVersion, object messageId, int errorCode, string errorMessage, object details) { var exception = new JsonRpcException(errorCode, errorMessage, details); var response = new JsonRpcResponse <object>() { Error = exception, Result = null, Id = messageId }; return(CreateErrorMessage(messageVersion, response)); }
public static string ToJson(JsonRpcException ex) { var dto = GetResponseContainer(); var error = new JObject(); error["code"] = ex.ErrorCode; error["message"] = ex.ErrorMessage; if (ex.ErrorData != null) { error["data"] = JToken.FromObject(ex.ErrorData); } dto["error"] = error; return(JsonConvert.SerializeObject(dto)); }
public void TestGetJsonWithData() { JObject data = new JObject(); data["d1"] = 42; data["d2"] = "42"; JsonRpcException exception = new JsonRpcException(42, "msg", data); JObject json = exception.GetJson(); Assert.AreEqual(42, (int)json["code"]); Assert.AreEqual("msg", (string)json["message"]); Assert.AreEqual(42, (int)json["data"]["d1"]); Assert.AreEqual("42", (string)json["data"]["d2"]); }
protected async Task <T> ExecuteAsync <T>(JsonRpcRequest <T> request) { T result = default(T); JsonRpcException rpcException = null; Exception exception = null; try { LoadingData = true; if (loadDelay > 0) { await Task.Delay(TimeSpan.FromSeconds(loadDelay)); } result = await JsonRpcClient.InvokeAsync <T>(request); } catch (AggregateException ex) { exception = ex; rpcException = ex.InnerException as JsonRpcException; } catch (JsonRpcException ex) { rpcException = ex; } catch (Exception ex) { exception = ex; } finally { LoadingData = false; } if (rpcException != null) { throw rpcException; } else if (exception != null) { var errorMessage = string.Format(CultureInfo.CurrentCulture, ResourceLoader.GetString("GeneralServiceErrorMessage"), Environment.NewLine, exception.Message); await AlertMessageService.ShowAsync(errorMessage, ResourceLoader.GetString("ErrorServiceUnreachable")); throw exception; } return(result); }
private void HandleInvalidShare(IShare share) { var miner = (IStratumMiner)share.Miner; miner.InvalidShares++; JsonRpcException exception = null; // the exception determined by the stratum error code. switch (share.Error) { case ShareError.DuplicateShare: exception = new DuplicateShareError(share.Nonce); break; case ShareError.IncorrectExtraNonce2Size: exception = new OtherError("Incorrect extranonce2 size"); break; case ShareError.IncorrectNTimeSize: exception = new OtherError("Incorrect nTime size"); break; case ShareError.IncorrectNonceSize: exception = new OtherError("Incorrect nonce size"); break; case ShareError.JobNotFound: exception = new JobNotFoundError(share.JobId); break; case ShareError.LowDifficultyShare: exception = new LowDifficultyShare(share.Difficulty); break; case ShareError.NTimeOutOfRange: exception = new OtherError("nTime out of range"); break; } JsonRpcContext.SetException(exception); // set the stratum exception within the json-rpc reply. Debug.Assert(exception != null); // exception should be never null when the share is marked as invalid. _logger.Debug("Rejected share by miner {0:l}, reason: {1:l}", miner.Username, exception.message); }
public void ProvideFault(Exception error, MessageVersion version, ref Message fault) { bool includeDetails = IncludeExceptionDetails(); // TODO: check error type and set appropriate error code object msgId = null; if (OperationContext.Current.IncomingMessageProperties.ContainsKey(DispatcherUtils.MessageIdKey)) msgId = OperationContext.Current.IncomingMessageProperties[DispatcherUtils.MessageIdKey]; // TODO: extract exception details from FaultException object additionalData; var faultException = error as FaultException; if (faultException != null && faultException.GetType().IsGenericType) { additionalData = faultException.GetType().GetProperty("Detail").GetValue(faultException, null); } else { additionalData = error; } var exception = new JsonRpcException(123, error.Message, additionalData); var errMessage = new JsonRpcResponse<object>() { Error = exception, Result = null, Id = msgId }; byte[] rawBody = DispatcherUtils.SerializeBody(errMessage, Encoding.UTF8); Message msg = DispatcherUtils.CreateMessage(version, "", rawBody, Encoding.UTF8); var property = (HttpResponseMessageProperty)msg.Properties[HttpResponseMessageProperty.Name]; property.StatusCode = HttpStatusCode.InternalServerError; property.StatusDescription = "Internal Server Error"; fault = msg; }
public static Message CreateErrorMessage(MessageVersion messageVersion, object messageId, JsonRpcException error) { var response = new JsonRpcResponse <object>() { Error = error, Result = null, Id = messageId }; return(CreateErrorMessage(messageVersion, response)); }
public static RpcError FromException(JsonRpcException ex) { return(new RpcError(ex.ErrorCode, ex.ErrorMessage, ex.ErrorData)); }
private string throwsException(string s, ref JsonRpcException refException) { refException = new JsonRpcException(-1, "This exception was thrown using: ref JsonRpcException", null); return(s); }
private string StringToRefException(string s, ref JsonRpcException refException) { refException = new JsonRpcException(-1, "refException worked", null); return(s); }
private void HandleInvalidShare(IShare share) { var miner = (IStratumMiner)share.Miner; if (share.Error != ShareError.NegativeDifficultyShareOutdatedMiner) { miner.InvalidShareCount++; } else { _logger.Debug("Got negative share from merit-miner 0.1.0 miner. Skipping"); } JsonRpcException exception = null; // the exception determined by the stratum error code. switch (share.Error) { case ShareError.DuplicateShare: exception = new DuplicateShareError(share.Nonce); break; case ShareError.IncorrectExtraNonce2Size: exception = new OtherError("Incorrect extranonce2 size"); break; case ShareError.IncorrectNTimeSize: exception = new OtherError("Incorrect nTime size"); break; case ShareError.IncorrectNonceSize: exception = new OtherError("Incorrect nonce size"); break; case ShareError.JobNotFound: exception = new JobNotFoundError(share.JobId); break; case ShareError.NegativeDifficultyShareOutdatedMiner: exception = new OtherError("Negative share: most likely old merit-miner used"); break; case ShareError.NegativeDifficultyShare: exception = new OtherError("Negative share"); break; case ShareError.LowDifficultyShare: exception = new LowDifficultyShare(share.Difficulty); break; case ShareError.NTimeOutOfRange: exception = new OtherError("nTime out of range"); break; case ShareError.IncorrectCycle: exception = new OtherError("Incorrect cycle"); break; } JsonRpcContext.SetException(exception); // set the stratum exception within the json-rpc reply. Debug.Assert(exception != null); // exception should be never null when the share is marked as invalid. _logger.Debug("Rejected share by miner {0:l}, reason: {1:l}", miner.Username, exception.message); }
public RpcCallException(JsonRpcException rpcError) : base(rpcError.Message) { this.RpcErrorCode = rpcError.Code; this.RpcErrorData = rpcError.Data; }