猎豆优选

MtopError.h 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. //
  2. // Error.h
  3. // mtopext
  4. //
  5. // Created by sihai on 4/11/14.
  6. // Copyright (c) 2014 Taobao. All rights reserved.
  7. //
  8. #import <Foundation/Foundation.h>
  9. #import <MtopSDK/TBSDKErrorRule.h>
  10. #import <mtopext/Constants.h>
  11. //@protocol TBSDKErrorRule;
  12. @interface MtopError : NSObject
  13. // http响应码
  14. @property(assign, nonatomic) int httpResponseCode;
  15. // 错误码
  16. @property(copy, nonatomic) NSString *code;
  17. // 错误提示信息
  18. @property(copy, nonatomic) NSString *msg;
  19. // 错误提示信息
  20. @property(copy, nonatomic) NSString *originalMsg;
  21. // 子错误码
  22. @property(copy, nonatomic) NSString *subCode;
  23. // 子错误提示信息
  24. @property(copy, nonatomic) NSString *subMsg;
  25. // 原始的错误
  26. @property(copy, nonatomic) NSError *rawError;
  27. // 新增错误映射码
  28. @property(copy, nonatomic) NSString *mappingCode;
  29. // 新增透传TBUIKit错误信息
  30. @property(strong, nonatomic) NSError *uikitError;
  31. // 新增420限流透出retCode错误信息
  32. @property(copy, nonatomic) NSString *limitFlowRawCode;
  33. /*!
  34. * 判断是否成功
  35. */
  36. - (BOOL) isSucceed;
  37. /*!
  38. * 初始化
  39. */
  40. - (instancetype)initWithHttpResponseCode:(int)httpResponseCode
  41. code: (NSString *)code
  42. msg:(NSString *)msg;
  43. /*!
  44. * 初始化
  45. */
  46. - (instancetype)initWithHttpResponseCode:(int)httpResponseCode
  47. code:(NSString *)code
  48. msg:(NSString *)msg
  49. subCode:(NSString *)subCode
  50. subMsg:(NSString *)subMsg;
  51. /*!
  52. * 为兼容, 转换成老的error
  53. * @return
  54. * id<TBSDKErrorRule>
  55. *
  56. */
  57. - (id<TBSDKErrorRule>)toTbsdkError;
  58. /*!
  59. * 判断是否为网络错误
  60. * @return
  61. * YES
  62. * NO
  63. */
  64. - (BOOL)isNetworkError;
  65. /*!
  66. * 判断是否为响应错误
  67. * @return
  68. * YES
  69. * NO
  70. */
  71. - (BOOL)isResponseDataParseError;
  72. /*!
  73. * 构造一个成功错误码
  74. */
  75. + (MtopError *)succeed;
  76. /**
  77. 构造透传的NSError
  78. @param code 错误码
  79. @param msg 错误信息
  80. @param responseCode 响应码
  81. @param mappingCode 错误映射码
  82. @return 透传的NSError
  83. */
  84. + (NSError *)createRawError:(NSString *)code msg:(NSString *)msg responseCode:(NSNumber *)responseCode mappingCode:(NSString *)mappingCode;
  85. @end