private JsonRpcResponse ReceiveMessage(string message)
        {
            JsonRpcResponse response;
            long            messageId = 0;

            try
            {
                JsonRpcMessage jsonRpcMessage = JsonConvert.DeserializeObject <JsonRpcMessage>(message);
                messageId = jsonRpcMessage.Id;
                try
                {
                    response = new JsonRpcResponse(jsonRpcMessage.Id, TryCallMethod(jsonRpcMessage).Result);
                }
                catch (Exception e)
                {
                    throw e.InnerException;
                }
            }
            catch (Exception e)
            {
                response = e switch
                {
                    JsonSerializationException _ => new JsonRpcResponse(messageId, JsonRpcErrors.ParseError),
                    MethodNotFoundException _ => new JsonRpcResponse(messageId, JsonRpcErrors.MethodNotFound),
                    InvalidParametersException _ => new JsonRpcResponse(messageId, JsonRpcErrors.InvalidParams),
                    FormatException _ => new JsonRpcResponse(messageId, JsonRpcErrors.InvalidParams),
                    _ => new JsonRpcResponse(messageId, JsonRpcErrors.InternalError)
                };
            }
            return(response);
        }
 public void InvalidParametersException_Serializes_InvalidParameters_Properly()
 {
     var ex = new InvalidParametersException(
         new InvalidParameter("Field", "This field is required")
     );
     var expected = "[{\"Field\":\"Field\",\"Errors\":[\"This field is required\"]}]";
     ex.InnerException.Message.Should().Be(expected);
 }
Beispiel #3
0
 private Task HandleInvalidParametersException(
     HttpContext httpContext, InvalidParametersException exception)
 {
     return(this.HandleProblem(
                httpContext,
                "Invalid parameters",
                StatusCodes.Status422UnprocessableEntity,
                exception));
 }
        public void InvalidParametersException_Creates_Parameters_Correctly()
        {
            var ex = new InvalidParametersException("Field", "This field is required");

            ex.Parameters.Should().HaveCount(1);
            ex.Parameters.First().Field.Should().Be("Field");

            ex.Parameters.First().Errors.Should().HaveCount(1);
            ex.Parameters.First().Errors.First().Should().Be("This field is required");
        }
Beispiel #5
0
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(InvalidParametersException obj)
 {
     return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr);
 }
Beispiel #6
0
 private static string GenerateInvalidParameterMessage(InvalidParametersException e)
 {
     return(new StringBuilder("Invalid parameters:").AppendLine()
            .Append(e.Message).ToString());
 }
Beispiel #7
0
 private static void PrintInvalidParameterError(InvalidParametersException e)
 {
     Console.WriteLine(GenerateInvalidParameterMessage(e));
 }