OnExceptionResult.cs 1023 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using JsonRPC4.Router.Abstractions;
  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 OnExceptionResult
  9. {
  10. public bool ThrowException
  11. {
  12. get;
  13. }
  14. public object ResponseObject
  15. {
  16. get;
  17. }
  18. private OnExceptionResult(bool throwException, object responseObject)
  19. {
  20. ThrowException = throwException;
  21. ResponseObject = responseObject;
  22. }
  23. public static OnExceptionResult UseObjectResponse(object responseObject)
  24. {
  25. return new OnExceptionResult(throwException: false, responseObject);
  26. }
  27. public static OnExceptionResult UseMethodResultResponse(IRpcMethodResult result)
  28. {
  29. return new OnExceptionResult(throwException: false, result);
  30. }
  31. public static OnExceptionResult UseExceptionResponse(Exception ex)
  32. {
  33. return new OnExceptionResult(throwException: true, ex);
  34. }
  35. public static OnExceptionResult DontHandle()
  36. {
  37. return new OnExceptionResult(throwException: true, null);
  38. }
  39. }
  40. }