GTLRErrorObject.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /* Copyright (c) 2011 Google Inc.
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. #import "GTLRObject.h"
  16. NS_ASSUME_NONNULL_BEGIN
  17. @class GTLRErrorObjectErrorItem;
  18. @class GTLRErrorObjectDetail;
  19. /**
  20. * This class wraps JSON responses (both V1 and V2 of Google JSON errors) and NSErrors.
  21. *
  22. * A GTLRErrorObject can be created using +objectWithJSON: or +objectWithFoundationError:
  23. */
  24. @interface GTLRErrorObject : GTLRObject
  25. /**
  26. * Convenience method for creating an error object from an NSError.
  27. *
  28. * @param error The @c NSError to be encapsulated by the @c GTLRErrorObject
  29. *
  30. * @return A @c GTLRErrorObject wrapping the NSError.
  31. */
  32. + (instancetype)objectWithFoundationError:(NSError *)error;
  33. /**
  34. * Convenience utility for extracting the GTLRErrorObject that was used to create an NSError.
  35. *
  36. * @param foundationError The NSError that may have been obtained from a GTLRErrorObject.
  37. *
  38. * @return The GTLRErrorObject, nil if the error was not originally from a GTLRErrorObject.
  39. */
  40. + (nullable GTLRErrorObject *)underlyingObjectForError:(NSError *)foundationError;
  41. //
  42. // V1 & V2 properties.
  43. //
  44. /**
  45. * The numeric error code.
  46. */
  47. @property(nonatomic, strong, nullable) NSNumber *code;
  48. /**
  49. * An error message string, typically provided by the API server. This is not localized,
  50. * and its reliability depends on the API server.
  51. */
  52. @property(nonatomic, strong, nullable) NSString *message;
  53. //
  54. // V1 properties.
  55. //
  56. /**
  57. * Underlying errors that occurred on the server.
  58. */
  59. @property(nonatomic, strong, nullable) NSArray<GTLRErrorObjectErrorItem *> *errors;
  60. //
  61. // V2 properties
  62. //
  63. /**
  64. * A status error string, defined by the API server, such as "NOT_FOUND".
  65. */
  66. @property(nonatomic, strong, nullable) NSString *status;
  67. /**
  68. * Additional diagnostic error details provided by the API server.
  69. */
  70. @property(nonatomic, strong, nullable) NSArray<GTLRErrorObjectDetail *> *details;
  71. /**
  72. * An NSError, either underlying the error object or manufactured from the error object's
  73. * properties.
  74. */
  75. @property(nonatomic, readonly) NSError *foundationError;
  76. @end
  77. /**
  78. * Class representing the items of the "errors" array inside the Google V1 error JSON.
  79. *
  80. * Client applications should not rely on the property values of these items.
  81. */
  82. @interface GTLRErrorObjectErrorItem : GTLRObject
  83. @property(nonatomic, strong, nullable) NSString *domain;
  84. @property(nonatomic, strong, nullable) NSString *reason;
  85. @property(nonatomic, strong, nullable) NSString *message;
  86. @property(nonatomic, strong, nullable) NSString *location;
  87. @end
  88. /**
  89. * Class representing the items of the "details" array inside the Google V2 error JSON.
  90. *
  91. * Client applications should not rely on the property values of these items.
  92. */
  93. @interface GTLRErrorObjectDetail : GTLRObject
  94. @property(nonatomic, strong, nullable) NSString *type;
  95. @property(nonatomic, strong, nullable) NSString *detail;
  96. @end
  97. NS_ASSUME_NONNULL_END