QNResponseInfo.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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. /**
  10. * 中途取消的状态码
  11. */
  12. extern const int kQNRequestCancelled;
  13. /**
  14. * 网络错误状态码
  15. */
  16. extern const int kQNNetworkError;
  17. /**
  18. * 错误参数状态码
  19. */
  20. extern const int kQNInvalidArgument;
  21. /**
  22. * 0 字节文件或数据
  23. */
  24. extern const int kQNZeroDataSize;
  25. /**
  26. * 错误token状态码
  27. */
  28. extern const int kQNInvalidToken;
  29. /**
  30. * 读取文件错误状态码
  31. */
  32. extern const int kQNFileError;
  33. /**
  34. * 上传完成后返回的状态信息
  35. */
  36. @interface QNResponseInfo : NSObject
  37. /**
  38. * 状态码
  39. */
  40. @property (readonly) int statusCode;
  41. /**
  42. * 七牛服务器生成的请求ID,用来跟踪请求信息,如果使用过程中出现问题,请反馈此ID
  43. */
  44. @property (nonatomic, copy, readonly) NSString *reqId;
  45. /**
  46. * 七牛服务器内部跟踪记录
  47. */
  48. @property (nonatomic, copy, readonly) NSString *xlog;
  49. /**
  50. * cdn服务器内部跟踪记录
  51. */
  52. @property (nonatomic, copy, readonly) NSString *xvia;
  53. /**
  54. * 错误信息,出错时请反馈此记录
  55. */
  56. @property (nonatomic, copy, readonly) NSError *error;
  57. /**
  58. * 服务器域名
  59. */
  60. @property (nonatomic, copy, readonly) NSString *host;
  61. /**
  62. * 请求消耗的时间,单位 秒
  63. */
  64. @property (nonatomic, readonly) double duration;
  65. /**
  66. * 服务器IP
  67. */
  68. @property (nonatomic, readonly) NSString *serverIp;
  69. /**
  70. * 客户端id
  71. */
  72. @property (nonatomic, readonly) NSString *id;
  73. /**
  74. * 时间戳
  75. */
  76. @property (readonly) UInt64 timeStamp;
  77. /**
  78. * 网络类型
  79. */
  80. //@property (nonatomic, readonly) NSString *networkType;
  81. /**
  82. * 是否取消
  83. */
  84. @property (nonatomic, readonly, getter=isCancelled) BOOL canceled;
  85. /**
  86. * 成功的请求
  87. */
  88. @property (nonatomic, readonly, getter=isOK) BOOL ok;
  89. /**
  90. * 是否网络错误
  91. */
  92. @property (nonatomic, readonly, getter=isConnectionBroken) BOOL broken;
  93. /**
  94. * 是否需要重试,内部使用
  95. */
  96. @property (nonatomic, readonly) BOOL couldRetry;
  97. /**
  98. * 是否需要换备用server,内部使用
  99. */
  100. @property (nonatomic, readonly) BOOL needSwitchServer;
  101. /**
  102. * 是否为 七牛响应
  103. */
  104. @property (nonatomic, readonly, getter=isNotQiniu) BOOL notQiniu;
  105. /**
  106. * 工厂函数,内部使用
  107. *
  108. * @return 取消的实例
  109. */
  110. + (instancetype)cancel;
  111. /**
  112. * 工厂函数,内部使用
  113. *
  114. * @param desc 错误参数描述
  115. *
  116. * @return 错误参数实例
  117. */
  118. + (instancetype)responseInfoWithInvalidArgument:(NSString *)desc;
  119. /**
  120. * 工厂函数,内部使用
  121. *
  122. * @param desc 错误token描述
  123. *
  124. * @return 错误token实例
  125. */
  126. + (instancetype)responseInfoWithInvalidToken:(NSString *)desc;
  127. /**
  128. * 工厂函数,内部使用
  129. *
  130. * @param error 错误信息
  131. * @param host 服务器域名
  132. * @param duration 请求完成时间,单位秒
  133. *
  134. * @return 网络错误实例
  135. */
  136. + (instancetype)responseInfoWithNetError:(NSError *)error
  137. host:(NSString *)host
  138. duration:(double)duration;
  139. /**
  140. * 工厂函数,内部使用
  141. *
  142. * @param error 错误信息
  143. *
  144. * @return 文件错误实例
  145. */
  146. + (instancetype)responseInfoWithFileError:(NSError *)error;
  147. /**
  148. * 工厂函数,内部使用
  149. *
  150. * @return 文件错误实例
  151. */
  152. + (instancetype)responseInfoOfZeroData:(NSString *)path;
  153. /**
  154. * 构造函数
  155. *
  156. * @param status 状态码
  157. * @param reqId 七牛服务器请求id
  158. * @param xlog 七牛服务器记录
  159. * @param body 服务器返回内容
  160. * @param host 服务器域名
  161. * @param duration 请求完成时间,单位秒
  162. *
  163. * @return 实例
  164. */
  165. - (instancetype)init:(int)status
  166. withReqId:(NSString *)reqId
  167. withXLog:(NSString *)xlog
  168. withXVia:(NSString *)xvia
  169. withHost:(NSString *)host
  170. withIp:(NSString *)ip
  171. withDuration:(double)duration
  172. withBody:(NSData *)body;
  173. @end