public JsonRpcException(JsonRpcClient jsonRpcClient, JsonRpcError error) : base($"{jsonRpcClient.Uri} returned Error {error.Code}: {error.Message}") { this.Uri = jsonRpcClient.Uri; this.Code = error.Code; this.ErrorMessage = error.Message; }
public static IJsonRpcHandlerBuilder UseSecurityExceptionHandler(this IJsonRpcHandlerBuilder builder) { return(builder.Use(async(context, next) => { try { await next(); } catch (Exception exception) { var securityException = exception.Unwrap <SecurityException>(); if (securityException != null) { // This is wrong: // 1) we are using exceptions for flow control // 2) sematically `SecurityException` means more `Forbidden` than `Unauthorized` // However - this get's the job done and I can't think of any better alternative without // introducing ton of boilerplate code. context.SetResponse(JsonRpcError.UNAUTHORIZED, $"{JsonRpcError.GetMessage(JsonRpcError.UNAUTHORIZED)} - {securityException.Message}"); } else { throw; } } })); }
public Task HandleExceptionAsync(HttpContext httpContext, Exception exception) { var response = httpContext.Response; response.StatusCode = (int)HttpStatusCode.InternalServerError; var err = JsonRpcError.CreateEmpty(); err.Error.Code = exception.HResult; err.Error.Message = exception.ToString(); var memoryStream = new MemoryStream(); using (var textWriter = new StreamWriter(memoryStream, Utilities.Utf8, Utilities.DefaultBufferSize, true)) { Utilities.Serializer.Serialize(textWriter, err); } memoryStream.Position = 0; response.Body = memoryStream; response.Headers[HttpHeader.ContentLength] = memoryStream.Length.ToString(CultureInfo.InvariantCulture); httpContext.CloseConnection = true; return(Task.FromResult(0)); }
//C++ TO C# CONVERTER WARNING: 'const' methods are not available in C#: //ORIGINAL LINE: bool getError(JsonRpcError& err) const public bool getError(JsonRpcError err) { if (!psResp.contains("error")) { return(false); } CryptoNote.GlobalMembers.loadFromJsonValue(err, psResp("error")); return(true); }
public void V2CoreSerializeResponseDataWhenHasDataIsTrueAnsIsNull() { var jsonSample = EmbeddedResourceManager.GetString("Assets.v2_core_error_has_data_true_null.json"); var jsonRpcSerializer = new JsonRpcSerializer(); var jsonRpcError = new JsonRpcError(0L, "m", null); var jsonRpcMessage = new JsonRpcResponse(jsonRpcError, 1L); var jsonResult = jsonRpcSerializer.SerializeResponse(jsonRpcMessage); CompareJsonStrings(jsonSample, jsonResult); }
protected override Type GetErrorDetailsDataType(JsonRpcError error) { if (error is object && error.Error is object && (int)error.Error.Code == (int)RemoteErrorCode.RemoteError) { return(typeof(RemoteError)); } return(base.GetErrorDetailsDataType(error)); }
protected override Type?GetErrorDetailsDataType(JsonRpcError error) { if ((int?)error?.Error?.Code == (int)RemoteErrorCode.RemoteError) { return(typeof(RemoteError)); } #pragma warning disable CS8604 // Possible null reference argument. return(base.GetErrorDetailsDataType(error)); #pragma warning restore CS8604 // Possible null reference argument. }
protected static void ReportError([NotNull] IRpcSessionContext context, [NotNull] Exception ex, [CanBeNull] object id = null) { var err = JsonRpcError.CreateEmpty(); err.Id = id; err.Error.Code = ex.HResult; err.Error.Message = ex.Message; var response = context.Response; response.StatusCode = (int)HttpStatusCode.OK; response.SetBody(err); }
public static JsonRpcResponse CreateJsonErrorResponse(int id, int code, string message, string data) { var error = new JsonRpcError(); error.Code = code; error.Data = data; error.Message = message; var resp = new JsonRpcResponse(); resp.JsonRpc = "2.0"; resp.Id = id; resp.Error = error; resp.Result = null; return resp; }
public void response_error() { var error = new JsonRpcError { Code = -1, Message = "Error Error" }; var r = FromJson(ToJson(new JsonRpcResponse { Id = 1, Error = error })); var ex = (JsonRpcException)Check.That(() => ((IRpcResponse)r).Exception is JsonRpcException); Check.That( () => ex.Code == error.Code, () => ex.Message == error.Message); }
// public Methods public JsonRpcResponse Login(JsonRpcRequest jsonRpcRequest) { var credentials = ((JObject)jsonRpcRequest.Params).ToObject <Credentials>(); //TODO login to external system Console.WriteLine(JsonConvert.SerializeObject(credentials)); var error = new JsonRpcError() { Code = ErrorCodes.E_Ok }; return(new JsonRpcResponse() { Id = jsonRpcRequest.Id, Error = error }); }
public void Resolver_ErrorData() { this.formatter.SetMessagePackSerializerOptions(MessagePackSerializerOptions.Standard.WithResolver(CompositeResolver.Create(new CustomFormatter()))); var originalErrorData = new TypeRequiringCustomFormatter { Prop1 = 3, Prop2 = 5 }; var originalError = new JsonRpcError { RequestId = new RequestId(1), Error = new JsonRpcError.ErrorDetail { Data = originalErrorData, }, }; var roundtripError = this.Roundtrip(originalError); var roundtripErrorData = roundtripError.Error !.GetData <TypeRequiringCustomFormatter>(); Assert.Equal(originalErrorData.Prop1, roundtripErrorData.Prop1); Assert.Equal(originalErrorData.Prop2, roundtripErrorData.Prop2); }
public void JsonRpcError() { var original = new JsonRpcError { RequestId = new RequestId(5), Error = new JsonRpcError.ErrorDetail { Code = JsonRpcErrorCode.InvocationError, Message = "Oops", Data = new CustomType { Age = 15 }, }, }; var actual = this.Roundtrip(original); Assert.Equal(original.RequestId, actual.RequestId); Assert.Equal(original.Error.Code, actual.Error !.Code); Assert.Equal(original.Error.Message, actual.Error.Message); Assert.Equal(((CustomType)original.Error.Data).Age, actual.Error.GetData <CustomType>().Age); }
// public Methods public JsonRpcResponse GetPickList(JsonRpcRequest jsonRpcRequest) { var pickRequest = ((JObject)jsonRpcRequest.Params).ToObject <Picklist>(); //TODO query WMS and return pickList var pickList = new Picklist() { Ident = pickRequest.Ident }; pickList.Lines.Add(new Pickline() { Ident = "1", Location = "01-05-34-04", Item = "Guinness", Quantity = 120M, Unit = "gallon" }); pickList.Lines.Add(new Pickline() { Ident = "2", Location = "01-08-46-01", Item = "Smithwick's", Quantity = 200M, Unit = "gallon" }); pickList.Lines.Add(new Pickline() { Ident = "3", Location = "01-12-11-03", Item = "Murphy's Irish Red", Quantity = 80M, Unit = "gallon" }); pickList.Lines.Add(new Pickline() { Ident = "4", Location = "01-22-34-05", Item = "Curim Gold Celtic Wheat", Quantity = 40M, Unit = "gallon" }); var error = new JsonRpcError() { Code = ErrorCodes.E_Ok }; return(new JsonRpcResponse() { Id = jsonRpcRequest.Id, Error = error, Result = pickList }); }
static async Task <Exception> GetExecutionTraceException(IJsonRpcClient rpcClient, JsonRpcError error) { var executionTrace = await rpcClient.GetExecutionTrace(); var traceAnalysis = new ExecutionTraceAnalysis(executionTrace); // Build our aggregate exception var aggregateException = traceAnalysis.GetAggregateException(error.ToException()); if (aggregateException == null) { throw new Exception("RPC error occurred with tracing enabled but no exceptions could be found in the trace data. Please report this issue.", error.ToException()); } return(aggregateException); }
public void HasDataIsTrue() { var jsonRpcError = new JsonRpcError(1L, "m", null); Assert.True(jsonRpcError.HasData); }
public void HasDataIsFalse() { var jsonRpcError = new JsonRpcError(1L, "m"); Assert.False(jsonRpcError.HasData); }
public void MessageIsEmptyString() { var jsonRpcError = new JsonRpcError(1L, string.Empty); Assert.Equal(string.Empty, jsonRpcError.Message); }
/// <summary> /// JsonRpc异常 /// </summary> /// <param name="error">错误内容</param> public JsonRpcException(JsonRpcError error) : base(error?.Message) { this.Error = error; }
public JsonRpcResponse(JsonRpcError ex, object id = null, object result = null) : base(ex, id, result) { }
public JsonRpcException(JsonRpcError err) : base($"Code={err.Code}, Message={err.Message._NonNull()}" + (err == null || err.Data == null ? "" : $", Data={err.Data._ObjectToJson(compact: true)}")) { this.RpcError = err !; }
public JsonRpcErrorResponse(JsonRpcMessageId id, JsonRpcError error, String message, String data = null) : base(id) { Error = error; Message = message; Data = data; }
public JsonRpcException(int code, object data = null) : base(JsonRpcError.GetMessage(code)) { JsonRpcCode = code; JsonRpcData = data; }
public static byte[] InvokeJsonRpc(byte[] json) { Debug.Assert(json != null); var jreq = (IDictionary <string, object>)PlainJsonConvert.Parse(json); //执行调用 object id; if (!jreq.TryGetValue(JsonRpcProtocol.Id, out id)) { return(GenerateResponse(new JsonRpcResponse() { Error = JsonRpcError.InvalidRequest, })); } object methodNameObj; if (!jreq.TryGetValue(JsonRpcProtocol.Method, out methodNameObj)) { return(GenerateResponse(new JsonRpcResponse() { Id = id, Error = JsonRpcError.InvalidRpcMethod })); } string methodName = (string)methodNameObj; MethodInfo method; if (!s_methods.TryGetValue(methodName, out method) || method == null) { return(GenerateResponse(new JsonRpcResponse() { Id = id, Error = JsonRpcError.InvalidRpcMethod })); } JsonRpcError error = null; object result = null; object argsObj; if (!jreq.TryGetValue(JsonRpcProtocol.Params, out argsObj)) { return(GenerateResponse(new JsonRpcResponse() { Id = id, Error = JsonRpcError.InvalidRpcMethod })); } var args = (object[])argsObj; LoggerProvider.RpcLogger.Debug(() => string.Format("JSON-RPC: method=[{0}], params=[{1}]", methodName, args)); try { var startTime = Stopwatch.GetTimestamp(); try { result = method.Invoke(null, args); } catch (TargetInvocationException tiex) { throw tiex.InnerException; } catch { throw; } var endTime = Stopwatch.GetTimestamp(); var costTime = endTime - startTime; LoggerProvider.RpcLogger.Debug( () => String.Format("Transaction costed time: [{0:N0}ms]", costTime * 1000 / Stopwatch.Frequency)); } catch (FatalException fex) { LoggerProvider.EnvironmentLogger.FatalException("FatalError", fex); throw fex; //接着抛出异常,让系统结束运行 } catch (ArgumentException ex) { error = JsonRpcError.RpcArgumentError; LoggerProvider.EnvironmentLogger.ErrorException("ArgumentException", ex); } catch (ValidationException ex) { error = JsonRpcError.ValidationError; LoggerProvider.EnvironmentLogger.ErrorException("ValidationException", ex); } catch (SecurityException ex) { error = JsonRpcError.SecurityError; LoggerProvider.EnvironmentLogger.ErrorException("SecurityError", ex); } catch (ResourceNotFoundException ex) { error = JsonRpcError.ResourceNotFound; LoggerProvider.EnvironmentLogger.ErrorException("ResourceNotFoundException", ex); } catch (RecordNotFoundException ex) { error = JsonRpcError.ResourceNotFound; LoggerProvider.EnvironmentLogger.ErrorException("ResourceNotFoundException", ex); } catch (DataException ex) { error = JsonRpcError.BadData; LoggerProvider.EnvironmentLogger.ErrorException("BadData", ex); } catch (System.Data.Common.DbException ex) { error = JsonRpcError.DBError; LoggerProvider.EnvironmentLogger.ErrorException("DBError", ex); } catch (System.Exception ex) { error = JsonRpcError.ServerInternalError; LoggerProvider.EnvironmentLogger.ErrorException("RPCHandler Error", ex); throw ex; //未知异常,与致命异常同样处理,直接抛出,让系统结束运行 } var jresponse = new JsonRpcResponse() { Id = id, Error = error, Result = result }; return(GenerateResponse(jresponse)); }
public JsonRpcResponse(object id, int errorCode, object errorData = null) : this(id, errorCode, JsonRpcError.GetMessage(errorCode), errorData : errorData) { }
public RDataAuthorizationException(JsonRpcError <string> error) : base(error) { }
public InvalidResponseException(JsonRpcResponse response, JsonRpcError error, string message) { Response = response; Error = error; Message = message; }
public RpcInternalServerErrorException(JsonRpcError error) : base(error.ToString()) { }
internal Type?GetErrorDetailsDataTypeHelper(JsonRpcError error) { return(GetErrorDetailsDataType(error)); }
public void CodeIsValid(long code) { var jsonRpcError = new JsonRpcError(code, "m"); Assert.Equal(code, jsonRpcError.Code); }
public void setError(JsonRpcError err) { psResp.set("error", CryptoNote.GlobalMembers.storeToJsonValue.functorMethod(err)); }
public RDataServerNotAvailableException(JsonRpcError <string> error) : base(error) { }