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); }
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"); }
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); }
private static string GenerateInvalidParameterMessage(InvalidParametersException e) { return(new StringBuilder("Invalid parameters:").AppendLine() .Append(e.Message).ToString()); }
private static void PrintInvalidParameterError(InvalidParametersException e) { Console.WriteLine(GenerateInvalidParameterMessage(e)); }