ExceptionFactory.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. * Copyright (C) Alibaba Cloud Computing
  3. * All rights reserved.
  4. *
  5. * 版权所有 (C)阿里云计算有限公司
  6. */
  7. using System;
  8. using Aliyun.OSS.Properties;
  9. using Aliyun.OSS.Common;
  10. namespace Aliyun.OSS.Util
  11. {
  12. internal static class ExceptionFactory
  13. {
  14. public static OssException CreateException(string errorCode,
  15. string message,
  16. string requestId,
  17. string hostId)
  18. {
  19. return CreateException(errorCode, message, requestId, hostId, null);
  20. }
  21. public static OssException CreateException(string errorCode,
  22. string message,
  23. string requestId,
  24. string hostId,
  25. Exception innerException)
  26. {
  27. var exception = innerException != null ?
  28. new OssException(message, innerException) :
  29. new OssException(message);
  30. exception.RequestId = requestId;
  31. exception.HostId = hostId;
  32. exception.ErrorCode = errorCode;
  33. return exception;
  34. }
  35. public static Exception CreateInvalidResponseException(Exception innerException)
  36. {
  37. throw new InvalidOperationException(Resources.ExceptionInvalidResponse, innerException);
  38. }
  39. }
  40. }