QNResponseInfo.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. //
  2. // QNResponseInfo.h
  3. // QiniuSDK
  4. //
  5. // Created by bailong on 14/10/2.
  6. // Copyright (c) 2014年 Qiniu. All rights reserved.
  7. //
  8. #import <Foundation/Foundation.h>
  9. @class QNHttpResponseInfo;
  10. /**
  11. * 中途取消的状态码
  12. */
  13. extern const int kQNRequestCancelled;
  14. /**
  15. * 网络错误状态码
  16. */
  17. extern const int kQNNetworkError;
  18. /**
  19. * 错误参数状态码
  20. */
  21. extern const int kQNInvalidArgument;
  22. /**
  23. * 0 字节文件或数据
  24. */
  25. extern const int kQNZeroDataSize;
  26. /**
  27. * 错误token状态码
  28. */
  29. extern const int kQNInvalidToken;
  30. /**
  31. * 读取文件错误状态码
  32. */
  33. extern const int kQNFileError;
  34. /**
  35. * 上传完成后返回的状态信息
  36. */
  37. @interface QNResponseInfo : NSObject
  38. /**
  39. * 状态码
  40. */
  41. @property (readonly) int statusCode;
  42. /**
  43. * 七牛服务器生成的请求ID,用来跟踪请求信息,如果使用过程中出现问题,请反馈此ID
  44. */
  45. @property (nonatomic, copy, readonly) NSString *reqId;
  46. /**
  47. * 七牛日志上报返回的X_Log_Client_Id
  48. */
  49. @property (nonatomic, copy, readonly) NSString *xClientId;
  50. /**
  51. * 七牛服务器内部跟踪记录
  52. */
  53. @property (nonatomic, copy, readonly) NSString *xlog;
  54. /**
  55. * cdn服务器内部跟踪记录
  56. */
  57. @property (nonatomic, copy, readonly) NSString *xvia;
  58. /**
  59. * 错误信息,出错时请反馈此记录
  60. */
  61. @property (nonatomic, copy, readonly) NSError *error;
  62. /**
  63. * 服务器域名
  64. */
  65. @property (nonatomic, copy, readonly) NSString *host;
  66. /**
  67. * 请求消耗的时间,单位 秒
  68. */
  69. @property (nonatomic, readonly) double duration;
  70. /**
  71. * 客户端id
  72. */
  73. @property (nonatomic, readonly) NSString *id;
  74. /**
  75. * 时间戳
  76. */
  77. @property (readonly) UInt64 timeStamp;
  78. /**
  79. * 是否取消
  80. */
  81. @property (nonatomic, readonly, getter=isCancelled) BOOL canceled;
  82. /**
  83. * 成功的请求
  84. */
  85. @property (nonatomic, readonly, getter=isOK) BOOL ok;
  86. /**
  87. * 是否网络错误
  88. */
  89. @property (nonatomic, readonly, getter=isConnectionBroken) BOOL broken;
  90. /**
  91. * 是否为 七牛响应
  92. */
  93. @property (nonatomic, readonly, getter=isNotQiniu) BOOL notQiniu;
  94. /**
  95. * 工厂函数,内部使用
  96. *
  97. * @param duration 请求完成时间,单位秒
  98. *
  99. * @return 取消的实例
  100. */
  101. + (instancetype)cancelWithDuration:(double)duration;
  102. /**
  103. * 工厂函数,内部使用
  104. *
  105. * @param desc 错误参数描述
  106. * @param duration 请求完成时间,单位秒
  107. *
  108. * @return 错误参数实例
  109. */
  110. + (instancetype)responseInfoWithInvalidArgument:(NSString *)desc duration:(double)duration;
  111. /**
  112. * 工厂函数,内部使用
  113. *
  114. * @param desc 错误token描述
  115. * @param duration 请求完成时间,单位秒
  116. *
  117. * @return 错误token实例
  118. */
  119. + (instancetype)responseInfoWithInvalidToken:(NSString *)desc duration:(double)duration;
  120. /**
  121. * 工厂函数,内部使用
  122. *
  123. * @param error 错误信息
  124. * @param duration 请求完成时间,单位秒
  125. *
  126. * @return 文件错误实例
  127. */
  128. + (instancetype)responseInfoWithFileError:(NSError *)error duration:(double)duration;
  129. /**
  130. * 工厂函数,内部使用
  131. *
  132. * @param path 文件路径
  133. * @param duration 请求完成时间,单位秒
  134. *
  135. * @return 文件错误实例
  136. */
  137. + (instancetype)responseInfoOfZeroData:(NSString *)path duration:(double)duration;
  138. /**
  139. * 工厂函数,内部使用
  140. *
  141. * @param httpResponseInfo 最后一次http请求的信息
  142. * @param duration 请求完成时间,单位秒
  143. *
  144. * @return 实例
  145. */
  146. + (instancetype)responseInfoWithHttpResponseInfo:(QNHttpResponseInfo *)httpResponseInfo duration:(double)duration;
  147. @end