FIRAuthErrorUtils.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. /*
  2. * Copyright 2017 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import <Foundation/Foundation.h>
  17. @class FIRPhoneAuthCredential;
  18. NS_ASSUME_NONNULL_BEGIN
  19. /** @class FIRAuthErrorUtils
  20. @brief Utility class used to construct @c NSError instances.
  21. */
  22. @interface FIRAuthErrorUtils : NSObject
  23. /** @fn RPCRequestEncodingErrorWithUnderlyingError
  24. @brief Constructs an @c NSError with the @c FIRAuthInternalErrorCodeRPCRequestEncodingError
  25. code and a populated @c NSUnderlyingErrorKey in the @c NSError.userInfo dictionary.
  26. @param underlyingError The value of the @c NSUnderlyingErrorKey key.
  27. @remarks This error is used when an @c FIRAuthRPCRequest.unencodedHTTPRequestBodyWithError:
  28. invocation returns an error. The error returned is wrapped in this internal error code.
  29. */
  30. + (NSError *)RPCRequestEncodingErrorWithUnderlyingError:(NSError *)underlyingError;
  31. /** @fn JSONSerializationErrorForUnencodableType
  32. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeJSONSerializationError code.
  33. @remarks This error is used when an @c NSJSONSerialization.isValidJSONObject: check fails, not
  34. for when an error is returned from @c NSJSONSerialization.dataWithJSONObject:options:error:.
  35. */
  36. + (NSError *)JSONSerializationErrorForUnencodableType;
  37. /** @fn JSONSerializationErrorWithUnderlyingError:
  38. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeJSONSerializationError code, and the
  39. @c underlyingError as the @c NSUnderlyingErrorKey value in the @c NSError.userInfo
  40. dictionary.
  41. @param underlyingError The value of the @c NSUnderlyingErrorKey key.
  42. @remarks This error is used when an invocation of
  43. @c NSJSONSerialization.dataWithJSONObject:options:error: returns an error.
  44. */
  45. + (NSError *)JSONSerializationErrorWithUnderlyingError:(NSError *)underlyingError;
  46. /** @fn networkErrorWithUnderlyingError:
  47. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeNetworkError code, and the
  48. @c underlyingError as the @c NSUnderlyingErrorKey value in the @c NSError.userInfo
  49. dictionary.
  50. @param underlyingError The value of the @c NSUnderlyingErrorKey key. Should be the error from
  51. GTM.
  52. @remarks This error is used when a network request results in an error, and no body data was
  53. returned.
  54. */
  55. + (NSError *)networkErrorWithUnderlyingError:(NSError *)underlyingError;
  56. /** @fn unexpectedErrorResponseWithUnderlyingError:
  57. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeNetworkError code, and the
  58. @c underlyingError as the @c NSUnderlyingErrorKey value.
  59. @param data The value of the @c FIRAuthErrorUserInfoDataKey key in the @c NSError.userInfo
  60. dictionary.
  61. @param underlyingError The value of the @c NSUnderlyingErrorKey key in the @c NSError.userInfo
  62. dictionary.
  63. @remarks This error is used when a network request results in an error, and unserializable body
  64. data was returned.
  65. */
  66. + (NSError *)unexpectedErrorResponseWithData:(NSData *)data
  67. underlyingError:(NSError *)underlyingError;
  68. /** @fn unexpectedErrorResponseWithDeserializedResponse:
  69. @brief Constructs an @c NSError with the @c FIRAuthInternalErrorCodeUnexpectedErrorResponse
  70. code, and a populated @c FIRAuthErrorUserInfoDeserializedResponseKey key in the
  71. @c NSError.userInfo dictionary.
  72. @param deserializedResponse The value of the @c FIRAuthErrorUserInfoDeserializedResponseKey key.
  73. @remarks This error is used when a network request results in an error, and the body data was
  74. deserializable as JSON, but couldn't be decoded as an error.
  75. */
  76. + (NSError *)unexpectedErrorResponseWithDeserializedResponse:(id)deserializedResponse;
  77. /** @fn unexpectedResponseWithData:underlyingError:
  78. @brief Constructs an @c NSError with the @c FIRAuthInternalErrorCodeUnexpectedResponse
  79. code, and a populated @c FIRAuthErrorUserInfoDataKey key in the @c NSError.userInfo
  80. dictionary.
  81. @param data The value of the @c FIRAuthErrorUserInfoDataKey key in the @c NSError.userInfo
  82. dictionary.
  83. @param underlyingError The value of the @c NSUnderlyingErrorKey key in the @c NSError.userInfo
  84. dictionary.
  85. @remarks This error is used when a network request is apparently successful, but the body data
  86. couldn't be deserialized as JSON.
  87. */
  88. + (NSError *)unexpectedResponseWithData:(NSData *)data
  89. underlyingError:(NSError *)underlyingError;;
  90. /** @fn unexpectedResponseWithDeserializedResponse:
  91. @brief Constructs an @c NSError with the @c FIRAuthInternalErrorCodeUnexpectedResponse
  92. code, and a populated @c FIRAuthErrorUserInfoDeserializedResponseKey key in the
  93. @c NSError.userInfo dictionary.
  94. @param deserializedResponse The value of the @c FIRAuthErrorUserInfoDeserializedResponseKey key.
  95. @remarks This error is used when a network request is apparently successful, the body data was
  96. successfully deserialized as JSON, but the JSON wasn't a dictionary.
  97. */
  98. + (NSError *)unexpectedResponseWithDeserializedResponse:(id)deserializedResponse;
  99. /** @fn unexpectedResponseWithDeserializedResponse:underlyingError:
  100. @brief Constructs an @c NSError with the @c FIRAuthInternalErrorCodeUnexpectedResponse
  101. code, and populated @c FIRAuthErrorUserInfoDeserializedResponseKey and
  102. @c NSUnderlyingErrorKey keys in the @c NSError.userInfo dictionary.
  103. @param deserializedResponse The value of the @c FIRAuthErrorUserInfoDeserializedResponseKey key.
  104. @param underlyingError The value of the @c NSUnderlyingErrorKey key.
  105. @remarks This error is used when a network request was apparently successful, the body data was
  106. successfully deserialized as JSON, but the data type of the response was unexpected.
  107. */
  108. + (NSError *)unexpectedResponseWithDeserializedResponse:(nullable id)deserializedResponse
  109. underlyingError:(NSError *)underlyingError;
  110. /** @fn RPCResponseDecodingErrorWithDeserializedResponse:underlyingError:
  111. @brief Constructs an @c NSError with the @c FIRAuthInternalErrorCodeRPCResponseDecodingError
  112. code, and populated @c FIRAuthErrorUserInfoDeserializedResponseKey and
  113. @c NSUnderlyingErrorKey keys in the @c NSError.userInfo dictionary.
  114. @param deserializedResponse The value of the @c FIRAuthErrorUserInfoDeserializedResponseKey key.
  115. @param underlyingError The value of the @c NSUnderlyingErrorKey key.
  116. @remarks This error is used when an invocation of @c FIRAuthRPCResponse.setWithDictionary:error:
  117. resulted in an error.
  118. */
  119. + (NSError *)RPCResponseDecodingErrorWithDeserializedResponse:(id)deserializedResponse
  120. underlyingError:(NSError *)underlyingError;
  121. /** @fn emailAlreadyInUseErrorWithEmail:
  122. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeEmailExists code.
  123. @param email The email address that is already in use.
  124. @return The NSError instance associated with the given FIRAuthError.
  125. */
  126. + (NSError *)emailAlreadyInUseErrorWithEmail:(nullable NSString *)email;
  127. /** @fn userDisabledErrorWithMessageWithMessage:
  128. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeUserDisabled code.
  129. @param message Error message from the backend, if any.
  130. @return The NSError instance associated with the given FIRAuthError.
  131. */
  132. + (NSError *)userDisabledErrorWithMessage:(nullable NSString *)message;
  133. /** @fn wrongPasswordErrorWithMessage:
  134. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeWrongPassword code.
  135. @param message Error message from the backend, if any.
  136. @return The NSError instance associated with the given FIRAuthError.
  137. */
  138. + (NSError *)wrongPasswordErrorWithMessage:(nullable NSString *)message;
  139. /** @fn tooManyRequestsErrorWithMessage:
  140. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeTooManyRequests Code.
  141. @param message Error message from the backend, if any.
  142. @return The NSError instance associated with the given FIRAuthError.
  143. */
  144. + (NSError *)tooManyRequestsErrorWithMessage:(nullable NSString *)message;
  145. /** @fn invalidCustomTokenErrorWithMessage:
  146. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeInvalidCustomToken code.
  147. @param message Error message from the backend, if any.
  148. @return The NSError instance associated with the given FIRAuthError.
  149. */
  150. + (NSError *)invalidCustomTokenErrorWithMessage:(nullable NSString *)message;
  151. /** @fn customTokenMistmatchErrorWithMessage:
  152. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeCustomTokenMismatch code.
  153. @param message Error message from the backend, if any.
  154. @return The NSError instance associated with the given FIRAuthError.
  155. */
  156. + (NSError *)customTokenMistmatchErrorWithMessage:(nullable NSString *)message;
  157. /** @fn invalidCredentialErrorWithMessage:
  158. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeInvalidCredential code.
  159. @param message Error message from the backend, if any.
  160. @return The NSError instance associated with the given FIRAuthError.
  161. */
  162. + (NSError *)invalidCredentialErrorWithMessage:(nullable NSString *)message;
  163. /** @fn requiresRecentLoginError
  164. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeRequiresRecentLogin code.
  165. @param message Error message from the backend, if any.
  166. @return The NSError instance associated with the given FIRAuthError.
  167. */
  168. + (NSError *)requiresRecentLoginErrorWithMessage:(nullable NSString *)message;
  169. /** @fn invalidUserTokenErrorWithMessage:
  170. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeInvalidUserToken code.
  171. @param message Error message from the backend, if any.
  172. @return The NSError instance associated with the given FIRAuthError.
  173. */
  174. + (NSError *)invalidUserTokenErrorWithMessage:(nullable NSString *)message;
  175. /** @fn invalidEmailErrorWithMessage:
  176. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeInvalidEmail code.
  177. @param message Error message from the backend, if any.
  178. @return The NSError instance associated with the given FIRAuthError.
  179. */
  180. + (NSError *)invalidEmailErrorWithMessage:(nullable NSString *)message;
  181. /** @fn accountExistsWithDifferentCredentialErrorWithEmail:
  182. @brief Constructs an @c NSError with the @c FIRAuthErrorAccountExistsWithDifferentCredential
  183. code.
  184. @param Email The email address that is already associated with an existing account
  185. @return The NSError instance associated with the given FIRAuthError.
  186. */
  187. + (NSError *)accountExistsWithDifferentCredentialErrorWithEmail:(nullable NSString *)Email;
  188. /** @fn providerAlreadyLinkedErrorWithMessage:
  189. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeProviderAlreadyLinked code.
  190. @return The NSError instance associated with the given FIRAuthError.
  191. */
  192. + (NSError *)providerAlreadyLinkedError;
  193. /** @fn noSuchProviderError
  194. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeNoSuchProvider code.
  195. @return The NSError instance associated with the given FIRAuthError.
  196. */
  197. + (NSError *)noSuchProviderError;
  198. /** @fn userTokenExpiredErrorWithMessage:
  199. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeUserTokenExpired code.
  200. @param message Error message from the backend, if any.
  201. @return The NSError instance associated with the given FIRAuthError.
  202. */
  203. + (NSError *)userTokenExpiredErrorWithMessage:(nullable NSString *)message;
  204. /** @fn userNotFoundErrorWithMessage:
  205. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeUserNotFound code.
  206. @param message Error message from the backend, if any.
  207. @return The NSError instance associated with the given FIRAuthError.
  208. */
  209. + (NSError *)userNotFoundErrorWithMessage:(nullable NSString *)message;
  210. /** @fn invalidLocalAPIKeyErrorWithMessage:
  211. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeInvalidAPIKey code.
  212. @return The NSError instance associated with the given FIRAuthError.
  213. */
  214. + (NSError *)invalidAPIKeyError;
  215. /** @fn userMismatchError
  216. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeUserMismatch code.
  217. @return The NSError instance associated with the given FIRAuthError.
  218. */
  219. + (NSError *)userMismatchError;
  220. /** @fn credentialAlreadyInUseErrorWithMessage:
  221. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeCredentialAlreadyInUse code.
  222. @param message Error message from the backend, if any.
  223. @param credential Auth credential to be added to the Error User Info dictionary.
  224. @return The NSError instance associated with the given FIRAuthError.
  225. */
  226. + (NSError *)credentialAlreadyInUseErrorWithMessage:(nullable NSString *)message
  227. credential:(nullable FIRPhoneAuthCredential *)credential;
  228. /** @fn operationNotAllowedErrorWithMessage:
  229. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeOperationNotAllowed code.
  230. @param message Error message from the backend, if any.
  231. @return The NSError instance associated with the given FIRAuthError.
  232. */
  233. + (NSError *)operationNotAllowedErrorWithMessage:(nullable NSString *)message;
  234. /** @fn weakPasswordErrorWithServerResponseReason:
  235. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeWeakPassword code.
  236. @param serverResponseReason A more detailed explanation string from server response.
  237. @return The NSError instance associated with the given FIRAuthError.
  238. */
  239. + (NSError *)weakPasswordErrorWithServerResponseReason:(NSString *)serverResponseReason;
  240. /** @fn appNotAuthorizedError
  241. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeAppNotAuthorized code.
  242. @return The NSError instance associated with the given FIRAuthError.
  243. */
  244. + (NSError *)appNotAuthorizedError;
  245. /** @fn expiredActionCodeErrorWithMessage:
  246. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeExpiredActionCode code.
  247. @param message Error message from the backend, if any.
  248. @return The NSError instance associated with the given FIRAuthError.
  249. */
  250. + (NSError *)expiredActionCodeErrorWithMessage:(nullable NSString *)message;
  251. /** @fn invalidActionCodeErrorWithMessage:
  252. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeInvalidActionCode code.
  253. @param message Error message from the backend, if any.
  254. @return The NSError instance associated with the given FIRAuthError.
  255. */
  256. + (NSError *)invalidActionCodeErrorWithMessage:(nullable NSString *)message;
  257. /** @fn invalidMessagePayloadError:
  258. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeInvalidMessagePayload code.
  259. @param message Error message from the backend, if any.
  260. @return The NSError instance associated with the given FIRAuthError.
  261. */
  262. + (NSError *)invalidMessagePayloadErrorWithMessage:(nullable NSString *)message;
  263. /** @fn invalidSenderErrorWithMessage:
  264. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeInvalidSender code.
  265. @param message Error message from the backend, if any.
  266. @return The NSError instance associated with the given FIRAuthError.
  267. */
  268. + (NSError *)invalidSenderErrorWithMessage:(nullable NSString *)message;
  269. /** @fn invalidRecipientEmailError:
  270. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeInvalidRecipientEmail code.
  271. @param message Error message from the backend, if any.
  272. @return The NSError instance associated with the given FIRAuthError.
  273. */
  274. + (NSError *)invalidRecipientEmailErrorWithMessage:(nullable NSString *)message;
  275. /** @fn missingEmail
  276. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeMissingEmail code.
  277. @return The NSError instance associated with the given FIRAuthError.
  278. */
  279. + (NSError *)missingEmail;
  280. /** @fn missingPhoneNumberErrorWithMessage:
  281. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeMissingPhoneNumber code.
  282. @param message Error message from the backend, if any.
  283. @return The NSError instance associated with the given FIRAuthError.
  284. */
  285. + (NSError *)missingPhoneNumberErrorWithMessage:(nullable NSString *)message;
  286. /** @fn invalidPhoneNumberErrorWithMessage:
  287. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeInvalidPhoneNumber code.
  288. @param message Error message from the backend, if any.
  289. @return The NSError instance associated with the given FIRAuthError.
  290. */
  291. + (NSError *)invalidPhoneNumberErrorWithMessage:(nullable NSString *)message;
  292. /** @fn missingVerificationCodeErrorWithMessage:
  293. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeMissingVerificationCode code.
  294. @param message Error message from the backend, if any.
  295. @return The NSError instance associated with the given FIRAuthError.
  296. */
  297. + (NSError *)missingVerificationCodeErrorWithMessage:(nullable NSString *)message;
  298. /** @fn invalidVerificationCodeErrorWithMessage:
  299. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeInvalidVerificationCode code.
  300. @param message Error message from the backend, if any.
  301. @return The NSError instance associated with the given FIRAuthError.
  302. */
  303. + (NSError *)invalidVerificationCodeErrorWithMessage:(nullable NSString *)message;
  304. /** @fn missingVerificationIDErrorWithMessage:
  305. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeMissingVerificationID code.
  306. @param message Error message from the backend, if any.
  307. @return The NSError instance associated with the given FIRAuthError.
  308. */
  309. + (NSError *)missingVerificationIDErrorWithMessage:(nullable NSString *)message;
  310. /** @fn invalidVerificationIDErrorWithMessage:
  311. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeInvalidVerificationID code.
  312. @param message Error message from the backend, if any.
  313. @return The NSError instance associated with the given FIRAuthError.
  314. */
  315. + (NSError *)invalidVerificationIDErrorWithMessage:(nullable NSString *)message;
  316. /** @fn sessionExpiredErrorWithMessage:
  317. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeSessionExpired code.
  318. @param message Error message from the backend, if any.
  319. @return The NSError instance associated with the given FIRAuthError.
  320. */
  321. + (NSError *)sessionExpiredErrorWithMessage:(nullable NSString *)message;
  322. /** @fn missingAppCredentialWithMessage:
  323. @brief Constructs an @c NSError with the @c FIRAuthErrorMissingCredential code.
  324. @param message Error message from the backend, if any.
  325. @return The NSError instance associated with the given FIRAuthError.
  326. */
  327. + (NSError *)missingAppCredentialWithMessage:(nullable NSString *)message;
  328. /** @fn invalidAppCredentialWithMessage:
  329. @brief Constructs an @c NSError with the @c FIRAuthErrorInvalidCredential code.
  330. @param message Error message from the backend, if any.
  331. @return The NSError instance associated with the given FIRAuthError.
  332. */
  333. + (NSError *)invalidAppCredentialWithMessage:(nullable NSString *)message;
  334. /** @fn quotaExceededErrorWithMessage:
  335. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeQuotaExceeded code.
  336. @param message Error message from the backend, if any.
  337. @return The NSError instance associated with the given FIRAuthError.
  338. */
  339. + (NSError *)quotaExceededErrorWithMessage:(nullable NSString *)message;
  340. /** @fn missingAppTokenError
  341. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeMissingAppToken code.
  342. @return The NSError instance associated with the given FIRAuthError.
  343. */
  344. + (NSError *)missingAppTokenError;
  345. /** @fn notificationNotForwardedError
  346. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeNotificationNotForwarded code.
  347. @return The NSError instance associated with the given FIRAuthError.
  348. */
  349. + (NSError *)notificationNotForwardedError;
  350. /** @fn appNotVerifiedErrorWithMessage:
  351. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeAppNotVerified code.
  352. @param message Error message from the backend, if any.
  353. @return The NSError instance associated with the given FIRAuthError.
  354. */
  355. + (NSError *)appNotVerifiedErrorWithMessage:(nullable NSString *)message;
  356. /** @fn keychainErrorWithFunction:status:
  357. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeKeychainError code.
  358. @param keychainFunction The keychain function which was invoked and yielded an unexpected
  359. response. The @c NSLocalizedFailureReasonErrorKey field in the @c NSError.userInfo
  360. dictionary will contain a string partially comprised of this value.
  361. @param status The response status from the invoked keychain function. The
  362. @c NSLocalizedFailureReasonErrorKey field in the @c NSError.userInfo dictionary will contain
  363. a string partially comprised of this value.
  364. */
  365. + (NSError *)keychainErrorWithFunction:(NSString *)keychainFunction status:(OSStatus)status;
  366. @end
  367. NS_ASSUME_NONNULL_END