public JsonRpcResponse(JsonRpcErrorCode rpcErrorCode, int originalErrorCode) : this(rpcErrorCode, null, null, originalErrorCode) { _rpcErrorCode = rpcErrorCode; _respBody = null; _exception = null; _originalErrorCode = originalErrorCode; }
private async Task <LspMessage> ReadMessage() { int contentLength = GetContentLength(); string msgString = await ReadString(contentLength).ConfigureAwait(false); JObject msgJson = JObject.Parse(msgString); if (msgJson.TryGetValue("method", out JToken methodToken)) { string method = ((JValue)methodToken).Value.ToString(); if (msgJson.TryGetValue("id", out JToken idToken)) { string requestId = ((JValue)idToken).Value.ToString(); return(new LspRequest(requestId, method, msgJson["params"])); } return(new LspNotification(method, msgJson["params"])); } string id = ((JValue)msgJson["id"]).Value.ToString(); if (msgJson.TryGetValue("result", out JToken resultToken)) { return(new LspSuccessfulResponse(id, resultToken)); } JObject errorBody = (JObject)msgJson["error"]; JsonRpcErrorCode errorCode = (JsonRpcErrorCode)(int)((JValue)errorBody["code"]).Value; string message = (string)((JValue)errorBody["message"]).Value; return(new LspErrorResponse(id, errorCode, message, errorBody["data"])); }
public JsonRpcResponse(JsonRpcErrorCode rpcErrorCode, string responseBody, JsonRpcException exception, int originalErrorCode) { _rpcErrorCode = rpcErrorCode; _respBody = responseBody; _exception = exception; _originalErrorCode = originalErrorCode; }
public JsonRpcErrorException(JsonRpcErrorCode errorCode, string message) : base(message) { Error = new JsonRpcError { Code = (long)errorCode, Message = message }; }
/// <summary> /// Initializes a new instance of the <see cref="RemoteMethodNotFoundException"/> class /// with supplied message and target method. /// </summary> /// <param name="message">Exception message describing why the method was not found.</param> /// <param name="targetMethod">Target method that was not found.</param> /// <param name="errorCode">The value of the error.code field in the response.</param> /// <param name="errorData">The value of the error.data field in the response.</param> /// <param name="deserializedErrorData">The value of the error.data field in the response, deserialized according to <see cref="JsonRpc.GetErrorDetailsDataType(JsonRpcError)"/>.</param> internal RemoteMethodNotFoundException(string?message, string targetMethod, JsonRpcErrorCode errorCode, object?errorData, object?deserializedErrorData) : base(message) { Requires.NotNullOrEmpty(targetMethod, nameof(targetMethod)); base.ErrorCode = errorCode; this.TargetMethod = targetMethod; base.ErrorData = errorData; base.DeserializedErrorData = deserializedErrorData; }
private void TrySetErrorResponse(RequestContext context, JsonRpcErrorCode errorCode, string message) { Logger.LogError("({code}) {message}", errorCode, message); if (context.Response == null) { return; } context.Response.Error = new ResponseError(errorCode, message); }
public LspErrorResponse( string id, JsonRpcErrorCode code, string message, JToken data) : base(id) { Code = code; Message = message; Data = data; }
public JsonRpcErrorException(JsonRpcErrorCode errorCode, string message, Exception ex) : base(message, ex) { Error = new JsonRpcError { Code = (long)errorCode, Message = message }; var dataDict = new Dictionary <string, object>(); dataDict["exception"] = ex.ToString(); // Populate the RPC data object with entries from the exception's Data dictionary. foreach (var item in ex.Data.Keys) { var dataVal = ex.Data[item]; if (dataVal != null) { dataDict[item.ToString()] = dataVal.ToString(); } } Error.Data = dataDict; }
public static JsonRpcMessage CreateError(JToken id, JsonRpcErrorCode error, string message, JObject data) { return(CreateError(id, (int)error, message, data)); }
public Error(JsonRpcErrorCode code, string message, JToken data) : this((int)code, message, data) { }
public ErrorResponseMessage(JsonRpcErrorCode errorCode, string errorMessage, string version = "2.0", string id = "") : base(version, id) { Error = new ErrorClass { Code = (int)errorCode, Message = errorMessage }; }
public void ReceivedError(long requestId, JsonRpcErrorCode errorCode) { this.WriteEvent(ReceivedErrorEvent, requestId, (long)errorCode); }
public void SendingError(long requestId, JsonRpcErrorCode errorCode) { this.WriteEvent(SendingErrorEvent, requestId, (long)errorCode); }
public JsonRpcResponse(JsonRpcErrorCode rpcErrorCode, string responseBody) : this(rpcErrorCode, responseBody, null, 0) { }
//public bool Wait() //{ // if (_waitHandle != null) // return _waitHandle.WaitOne(_timeOut + 10000); // return false; //} private static void ResponseCallback(IAsyncResult asyncResult) { //Console.WriteLine("接收应答222222222222222" + DateTime.Now.ToShortDateString()); JsonRpcHttpClientTransaction trans = (JsonRpcHttpClientTransaction)asyncResult.AsyncState; JsonRpcResponse response = null; WebResponse webResponse = null; try { webResponse = trans._webRequest.EndGetResponse(asyncResult); trans._webResponse = webResponse; string warn = webResponse.Headers.Get("UU-RESPONSE-RC"); string lengthStr = webResponse.Headers.Get("UU-CONTENT-LENGTH"); int length = 0; int.TryParse(lengthStr + "", out length); int orginalErrorCode = 0; int.TryParse(warn, out orginalErrorCode); string respBody = null; if (length > 0) { Stream stream = webResponse.GetResponseStream(); StreamReader readerStream = new StreamReader(stream); respBody = readerStream.ReadToEnd(); readerStream.Close(); } if (!string.IsNullOrEmpty(warn) && warn != "0") { JsonRpcErrorCode errCode = JsonRpcErrorCode.Unknown; Enum.TryParse <JsonRpcErrorCode>(warn, true, out errCode); response = new JsonRpcResponse(errCode, respBody, new JsonRpcException(trans._sericeUri, respBody, new Exception("rc != 0")), orginalErrorCode); } else { response = new JsonRpcResponse(JsonRpcErrorCode.OK, respBody); } TracingManager.Info( delegate() { string responseCode = warn == null ? "0" : warn; _tracing.Info(string.Format("jsonrpc response:response rc ={0}\r\nresponse body:{1}", responseCode, respBody)); //if (responseCode != "0") //{ // _tracing.ErrorFmt(response.Exception, "web data response error ,originalerrorcode is {0}", orginalErrorCode); //} } ); } catch (WebException ex) { if (ex.Status == WebExceptionStatus.Timeout) { response = new JsonRpcResponse(JsonRpcErrorCode.TransactionTimeout, new JsonRpcException(null, null, ex), 500); } else { response = new JsonRpcResponse(JsonRpcErrorCode.SendFailed, new JsonRpcException(null, null, ex), 500); } } catch (Exception ex) { SystemLog.Error(LogEventID.RpcFailed, ex, "SendRequest failed"); response = new JsonRpcResponse(JsonRpcErrorCode.SendFailed, new JsonRpcException(null, null, ex), 500); } finally { if (webResponse != null) { webResponse.Close(); } trans.OnCallback(response); } }
public ResponseError(JsonRpcErrorCode code, string message) : this(code, message, null) { }
public JsonRpcResponse(JsonRpcErrorCode rpcErrorCode, JsonRpcException exception, int orginalErrorCode) : this(rpcErrorCode, null, exception, orginalErrorCode) { }
public JsonRpcResponse(JsonRpcErrorCode rpcErrorCode) : this (rpcErrorCode, 0) { }
public ResponseError(JsonRpcErrorCode code, string message, object data) : this((int)code, message, data) { }
public JsonRpcException(string message, JsonRpcErrorCode jsonRpcErrorCode) : base(message) { JsonRpcErrorCode = jsonRpcErrorCode; }