RpcResponse.cs 770 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using JsonRPC4.Common;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Threading.Tasks;
  6. namespace JsonRPC4.Router
  7. {
  8. public class RpcResponse
  9. {
  10. public RpcId Id
  11. {
  12. get;
  13. private set;
  14. }
  15. public object Result
  16. {
  17. get;
  18. private set;
  19. }
  20. public RpcError Error
  21. {
  22. get;
  23. private set;
  24. }
  25. public bool HasError => Error != null;
  26. protected RpcResponse()
  27. {
  28. }
  29. protected RpcResponse(RpcId id)
  30. {
  31. Id = id;
  32. }
  33. public RpcResponse(RpcId id, RpcError error)
  34. : this(id)
  35. {
  36. Error = error;
  37. }
  38. public RpcResponse(RpcId id, object result)
  39. : this(id)
  40. {
  41. Result = result;
  42. }
  43. public void ThrowErrorIfExists()
  44. {
  45. if (HasError)
  46. {
  47. throw Error.CreateException();
  48. }
  49. }
  50. }
  51. }