FIRAuthErrorUtils.h 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  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. #import "FirebaseAuth/Sources/Public/FirebaseAuth/FIRAuth.h"
  18. #import "FirebaseAuth/Sources/Public/FirebaseAuth/FIRMultiFactorInfo.h"
  19. #import "FirebaseAuth/Sources/Utilities/FIRAuthInternalErrors.h"
  20. @class FIRAuthCredential;
  21. NS_ASSUME_NONNULL_BEGIN
  22. /** @var kMissingRecaptchaTokenErrorPrefix
  23. @brief The prefix of the error message of missing recaptcha token during authenticating.
  24. */
  25. static NSString *const kMissingRecaptchaTokenErrorPrefix = @"MISSING_RECAPTCHA_TOKEN";
  26. /** @class FIRAuthErrorUtils
  27. @brief Utility class used to construct @c NSError instances.
  28. */
  29. @interface FIRAuthErrorUtils : NSObject
  30. + (NSError *)errorWithCode:(FIRAuthInternalErrorCode)code message:(nullable NSString *)message;
  31. /** @fn RPCRequestEncodingErrorWithUnderlyingError
  32. @brief Constructs an @c NSError with the @c FIRAuthInternalErrorCodeRPCRequestEncodingError
  33. code and a populated @c NSUnderlyingErrorKey in the @c NSError.userInfo dictionary.
  34. @param underlyingError The value of the @c NSUnderlyingErrorKey key.
  35. @remarks This error is used when an @c FIRAuthRPCRequest.unencodedHTTPRequestBodyWithError:
  36. invocation returns an error. The error returned is wrapped in this internal error code.
  37. */
  38. + (NSError *)RPCRequestEncodingErrorWithUnderlyingError:(NSError *)underlyingError;
  39. /** @fn JSONSerializationErrorForUnencodableType
  40. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeJSONSerializationError code.
  41. @remarks This error is used when an @c NSJSONSerialization.isValidJSONObject: check fails, not
  42. for when an error is returned from @c NSJSONSerialization.dataWithJSONObject:options:error:.
  43. */
  44. + (NSError *)JSONSerializationErrorForUnencodableType;
  45. /** @fn JSONSerializationErrorWithUnderlyingError:
  46. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeJSONSerializationError code, and the
  47. @c underlyingError as the @c NSUnderlyingErrorKey value in the @c NSError.userInfo
  48. dictionary.
  49. @param underlyingError The value of the @c NSUnderlyingErrorKey key.
  50. @remarks This error is used when an invocation of
  51. @c NSJSONSerialization.dataWithJSONObject:options:error: returns an error.
  52. */
  53. + (NSError *)JSONSerializationErrorWithUnderlyingError:(NSError *)underlyingError;
  54. /** @fn networkErrorWithUnderlyingError:
  55. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeNetworkError code, and the
  56. @c underlyingError as the @c NSUnderlyingErrorKey value in the @c NSError.userInfo
  57. dictionary.
  58. @param underlyingError The value of the @c NSUnderlyingErrorKey key. Should be the error from
  59. GTM.
  60. @remarks This error is used when a network request results in an error, and no body data was
  61. returned.
  62. */
  63. + (NSError *)networkErrorWithUnderlyingError:(NSError *)underlyingError;
  64. /** @fn unexpectedErrorResponseWithUnderlyingError:
  65. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeNetworkError code, and the
  66. @c underlyingError as the @c NSUnderlyingErrorKey value.
  67. @param data The value of the @c FIRAuthErrorUserInfoDataKey key in the @c NSError.userInfo
  68. dictionary.
  69. @param underlyingError The value of the @c NSUnderlyingErrorKey key in the @c NSError.userInfo
  70. dictionary.
  71. @remarks This error is used when a network request results in an error, and unserializable body
  72. data was returned.
  73. */
  74. + (NSError *)unexpectedErrorResponseWithData:(NSData *)data
  75. underlyingError:(NSError *)underlyingError;
  76. /** @fn unexpectedErrorResponseWithDeserializedResponse:
  77. @brief Constructs an @c NSError with the @c FIRAuthInternalErrorCodeUnexpectedErrorResponse
  78. code, and a populated @c FIRAuthErrorUserInfoDeserializedResponseKey key in the
  79. @c NSError.userInfo dictionary.
  80. @param deserializedResponse The value of the @c FIRAuthErrorUserInfoDeserializedResponseKey key.
  81. @remarks This error is used when a network request results in an error, and the body data was
  82. deserializable as JSON, but couldn't be decoded as an error.
  83. */
  84. + (NSError *)unexpectedErrorResponseWithDeserializedResponse:(id)deserializedResponse;
  85. /** @fn unexpectedErrorResponseWithDeserializedResponse:underlyingError:
  86. @brief Constructs an @c NSError with the @c FIRAuthInternalErrorCodeUnexpectedErrorResponse
  87. code, and populated @c FIRAuthErrorUserInfoDeserializedResponseKey and
  88. @c NSUnderlyingErrorKey keys in the @c NSError.userInfo dictionary.
  89. @param deserializedResponse The value of the @c FIRAuthErrorUserInfoDeserializedResponseKey key.
  90. @param underlyingError The value of the @c NSUnderlyingErrorKey key.
  91. @remarks This error is used when a network request results in an error, and the body data was
  92. deserializable as JSON, but couldn't be decoded as an error.
  93. */
  94. + (NSError *)unexpectedErrorResponseWithDeserializedResponse:(id)deserializedResponse
  95. underlyingError:(NSError *)underlyingError;
  96. /** @fn malformedJWTErrorWithToken:underlyingError:
  97. @brief Constructs an @c NSError with the code set to @c FIRAuthErrorCodeMalformedJWT and
  98. populates the userInfo dictionary with an error message, the bad token, and an underlying
  99. error that may have occurred when parsing.
  100. @param token The token that failed to parse.
  101. @param underlyingError The error that caused this error. If this parameter is nil, the
  102. NSUnderlyingErrorKey value will not be set.
  103. @remarks This error is returned when JWT parsing fails.
  104. @return An @c FIRAuthErrorCodeMalformedJWT error wrapping an underlying error, if available.
  105. */
  106. + (NSError *)malformedJWTErrorWithToken:(NSString *)token
  107. underlyingError:(NSError *_Nullable)underlyingError;
  108. /** @fn unexpectedResponseWithData:underlyingError:
  109. @brief Constructs an @c NSError with the @c FIRAuthInternalErrorCodeUnexpectedResponse
  110. code, and a populated @c FIRAuthErrorUserInfoDataKey key in the @c NSError.userInfo
  111. dictionary.
  112. @param data The value of the @c FIRAuthErrorUserInfoDataKey key in the @c NSError.userInfo
  113. dictionary.
  114. @param underlyingError The value of the @c NSUnderlyingErrorKey key in the @c NSError.userInfo
  115. dictionary.
  116. @remarks This error is used when a network request is apparently successful, but the body data
  117. couldn't be deserialized as JSON.
  118. */
  119. + (NSError *)unexpectedResponseWithData:(NSData *)data underlyingError:(NSError *)underlyingError;
  120. ;
  121. /** @fn unexpectedResponseWithDeserializedResponse:
  122. @brief Constructs an @c NSError with the @c FIRAuthInternalErrorCodeUnexpectedResponse
  123. code, and a populated @c FIRAuthErrorUserInfoDeserializedResponseKey key in the
  124. @c NSError.userInfo dictionary.
  125. @param deserializedResponse The value of the @c FIRAuthErrorUserInfoDeserializedResponseKey key.
  126. @remarks This error is used when a network request is apparently successful, the body data was
  127. successfully deserialized as JSON, but the JSON wasn't a dictionary.
  128. */
  129. + (NSError *)unexpectedResponseWithDeserializedResponse:(id)deserializedResponse;
  130. /** @fn unexpectedResponseWithDeserializedResponse:underlyingError:
  131. @brief Constructs an @c NSError with the @c FIRAuthInternalErrorCodeUnexpectedResponse
  132. code, and populated @c FIRAuthErrorUserInfoDeserializedResponseKey and
  133. @c NSUnderlyingErrorKey keys in the @c NSError.userInfo dictionary.
  134. @param deserializedResponse The value of the @c FIRAuthErrorUserInfoDeserializedResponseKey key.
  135. @param underlyingError The value of the @c NSUnderlyingErrorKey key.
  136. @remarks This error is used when a network request was apparently successful, the body data was
  137. successfully deserialized as JSON, but the data type of the response was unexpected.
  138. */
  139. + (NSError *)unexpectedResponseWithDeserializedResponse:(nullable id)deserializedResponse
  140. underlyingError:(NSError *)underlyingError;
  141. /** @fn RPCResponseDecodingErrorWithDeserializedResponse:underlyingError:
  142. @brief Constructs an @c NSError with the @c FIRAuthInternalErrorCodeRPCResponseDecodingError
  143. code, and populated @c FIRAuthErrorUserInfoDeserializedResponseKey and
  144. @c NSUnderlyingErrorKey keys in the @c NSError.userInfo dictionary.
  145. @param deserializedResponse The value of the @c FIRAuthErrorUserInfoDeserializedResponseKey key.
  146. @param underlyingError The value of the @c NSUnderlyingErrorKey key.
  147. @remarks This error is used when an invocation of @c FIRAuthRPCResponse.setWithDictionary:error:
  148. resulted in an error.
  149. */
  150. + (NSError *)RPCResponseDecodingErrorWithDeserializedResponse:(id)deserializedResponse
  151. underlyingError:(NSError *)underlyingError;
  152. /** @fn emailAlreadyInUseErrorWithEmail:
  153. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeEmailExists code.
  154. @param email The email address that is already in use.
  155. @return The NSError instance associated with the given FIRAuthError.
  156. */
  157. + (NSError *)emailAlreadyInUseErrorWithEmail:(nullable NSString *)email;
  158. /** @fn userDisabledErrorWithMessageWithMessage:
  159. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeUserDisabled code.
  160. @param message Error message from the backend, if any.
  161. @return The NSError instance associated with the given FIRAuthError.
  162. */
  163. + (NSError *)userDisabledErrorWithMessage:(nullable NSString *)message;
  164. /** @fn wrongPasswordErrorWithMessage:
  165. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeWrongPassword code.
  166. @param message Error message from the backend, if any.
  167. @return The NSError instance associated with the given FIRAuthError.
  168. */
  169. + (NSError *)wrongPasswordErrorWithMessage:(nullable NSString *)message;
  170. /** @fn tooManyRequestsErrorWithMessage:
  171. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeTooManyRequests Code.
  172. @param message Error message from the backend, if any.
  173. @return The NSError instance associated with the given FIRAuthError.
  174. */
  175. + (NSError *)tooManyRequestsErrorWithMessage:(nullable NSString *)message;
  176. /** @fn invalidCustomTokenErrorWithMessage:
  177. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeInvalidCustomToken code.
  178. @param message Error message from the backend, if any.
  179. @return The NSError instance associated with the given FIRAuthError.
  180. */
  181. + (NSError *)invalidCustomTokenErrorWithMessage:(nullable NSString *)message;
  182. /** @fn customTokenMistmatchErrorWithMessage:
  183. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeCustomTokenMismatch code.
  184. @param message Error message from the backend, if any.
  185. @return The NSError instance associated with the given FIRAuthError.
  186. */
  187. + (NSError *)customTokenMistmatchErrorWithMessage:(nullable NSString *)message;
  188. /** @fn invalidCredentialErrorWithMessage:
  189. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeInvalidCredential code.
  190. @param message Error message from the backend, if any.
  191. @return The NSError instance associated with the given FIRAuthError.
  192. */
  193. + (NSError *)invalidCredentialErrorWithMessage:(nullable NSString *)message;
  194. /** @fn requiresRecentLoginError
  195. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeRequiresRecentLogin code.
  196. @param message Error message from the backend, if any.
  197. @return The NSError instance associated with the given FIRAuthError.
  198. */
  199. + (NSError *)requiresRecentLoginErrorWithMessage:(nullable NSString *)message;
  200. /** @fn invalidUserTokenErrorWithMessage:
  201. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeInvalidUserToken code.
  202. @param message Error message from the backend, if any.
  203. @return The NSError instance associated with the given FIRAuthError.
  204. */
  205. + (NSError *)invalidUserTokenErrorWithMessage:(nullable NSString *)message;
  206. /** @fn invalidEmailErrorWithMessage:
  207. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeInvalidEmail code.
  208. @param message Error message from the backend, if any.
  209. @return The NSError instance associated with the given FIRAuthError.
  210. */
  211. + (NSError *)invalidEmailErrorWithMessage:(nullable NSString *)message;
  212. /** @fn accountExistsWithDifferentCredentialErrorWithEmail:
  213. @brief Constructs an @c NSError with the @c FIRAuthErrorAccountExistsWithDifferentCredential
  214. code.
  215. @param email The email address that is already associated with an existing account
  216. @param updatedCredential The updated credential for the existing account
  217. @return The NSError instance associated with the given FIRAuthError.
  218. */
  219. + (NSError *)accountExistsWithDifferentCredentialErrorWithEmail:(nullable NSString *)email
  220. updatedCredential:
  221. (nullable FIRAuthCredential *)updatedCredential;
  222. /** @fn providerAlreadyLinkedErrorWithMessage:
  223. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeProviderAlreadyLinked code.
  224. @return The NSError instance associated with the given FIRAuthError.
  225. */
  226. + (NSError *)providerAlreadyLinkedError;
  227. /** @fn noSuchProviderError
  228. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeNoSuchProvider code.
  229. @return The NSError instance associated with the given FIRAuthError.
  230. */
  231. + (NSError *)noSuchProviderError;
  232. /** @fn userTokenExpiredErrorWithMessage:
  233. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeUserTokenExpired code.
  234. @param message Error message from the backend, if any.
  235. @return The NSError instance associated with the given FIRAuthError.
  236. */
  237. + (NSError *)userTokenExpiredErrorWithMessage:(nullable NSString *)message;
  238. /** @fn userNotFoundErrorWithMessage:
  239. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeUserNotFound code.
  240. @param message Error message from the backend, if any.
  241. @return The NSError instance associated with the given FIRAuthError.
  242. */
  243. + (NSError *)userNotFoundErrorWithMessage:(nullable NSString *)message;
  244. /** @fn invalidLocalAPIKeyErrorWithMessage:
  245. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeInvalidAPIKey code.
  246. @return The NSError instance associated with the given FIRAuthError.
  247. */
  248. + (NSError *)invalidAPIKeyError;
  249. /** @fn userMismatchError
  250. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeUserMismatch code.
  251. @return The NSError instance associated with the given FIRAuthError.
  252. */
  253. + (NSError *)userMismatchError;
  254. /** @fn credentialAlreadyInUseErrorWithMessage:email:
  255. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeCredentialAlreadyInUse code.
  256. @param message Error message from the backend, if any.
  257. @param credential Auth credential to be added to the Error User Info dictionary.
  258. @param email Email to be added to the Error User Info dictionary.
  259. @return The NSError instance associated with the given FIRAuthError.
  260. */
  261. + (NSError *)credentialAlreadyInUseErrorWithMessage:(nullable NSString *)message
  262. credential:(nullable FIRAuthCredential *)credential
  263. email:(nullable NSString *)email;
  264. /** @fn operationNotAllowedErrorWithMessage:
  265. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeOperationNotAllowed code.
  266. @param message Error message from the backend, if any.
  267. @return The NSError instance associated with the given FIRAuthError.
  268. */
  269. + (NSError *)operationNotAllowedErrorWithMessage:(nullable NSString *)message;
  270. /** @fn weakPasswordErrorWithServerResponseReason:
  271. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeWeakPassword code.
  272. @param serverResponseReason A more detailed explanation string from server response.
  273. @return The NSError instance associated with the given FIRAuthError.
  274. */
  275. + (NSError *)weakPasswordErrorWithServerResponseReason:(nullable NSString *)serverResponseReason;
  276. /** @fn appNotAuthorizedError
  277. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeAppNotAuthorized code.
  278. @return The NSError instance associated with the given FIRAuthError.
  279. */
  280. + (NSError *)appNotAuthorizedError;
  281. /** @fn expiredActionCodeErrorWithMessage:
  282. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeExpiredActionCode code.
  283. @param message Error message from the backend, if any.
  284. @return The NSError instance associated with the given FIRAuthError.
  285. */
  286. + (NSError *)expiredActionCodeErrorWithMessage:(nullable NSString *)message;
  287. /** @fn invalidActionCodeErrorWithMessage:
  288. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeInvalidActionCode code.
  289. @param message Error message from the backend, if any.
  290. @return The NSError instance associated with the given FIRAuthError.
  291. */
  292. + (NSError *)invalidActionCodeErrorWithMessage:(nullable NSString *)message;
  293. /** @fn invalidMessagePayloadError:
  294. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeInvalidMessagePayload code.
  295. @param message Error message from the backend, if any.
  296. @return The NSError instance associated with the given FIRAuthError.
  297. */
  298. + (NSError *)invalidMessagePayloadErrorWithMessage:(nullable NSString *)message;
  299. /** @fn invalidSenderErrorWithMessage:
  300. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeInvalidSender code.
  301. @param message Error message from the backend, if any.
  302. @return The NSError instance associated with the given FIRAuthError.
  303. */
  304. + (NSError *)invalidSenderErrorWithMessage:(nullable NSString *)message;
  305. /** @fn invalidRecipientEmailError:
  306. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeInvalidRecipientEmail code.
  307. @param message Error message from the backend, if any.
  308. @return The NSError instance associated with the given FIRAuthError.
  309. */
  310. + (NSError *)invalidRecipientEmailErrorWithMessage:(nullable NSString *)message;
  311. /** @fn missingIosBundleIDErrorWithMessage:
  312. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeMissingIosBundleID code.
  313. @param message Error message from the backend, if any.
  314. @return The NSError instance associated with the given FIRAuthError.
  315. */
  316. + (NSError *)missingIosBundleIDErrorWithMessage:(nullable NSString *)message;
  317. /** @fn missingAndroidPackageNameErrorWithMessage:
  318. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeMissingAndroidPackageName code.
  319. @param message Error message from the backend, if any.
  320. @return The NSError instance associated with the given FIRAuthError.
  321. */
  322. + (NSError *)missingAndroidPackageNameErrorWithMessage:(nullable NSString *)message;
  323. /** @fn unauthorizedDomainErrorWithMessage:
  324. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeUnauthorizedDomain code.
  325. @param message Error message from the backend, if any.
  326. @return The NSError instance associated with the given FIRAuthError.
  327. */
  328. + (NSError *)unauthorizedDomainErrorWithMessage:(nullable NSString *)message;
  329. /** @fn invalidContinueURIErrorWithMessage:
  330. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeInvalidContinueURI code.
  331. @param message Error message from the backend, if any.
  332. @return The NSError instance associated with the given FIRAuthError.
  333. */
  334. + (NSError *)invalidContinueURIErrorWithMessage:(nullable NSString *)message;
  335. /** @fn missingContinueURIErrorWithMessage:
  336. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeMissingContinueURI code.
  337. @param message Error message from the backend, if any.
  338. @return The NSError instance associated with the given FIRAuthError.
  339. */
  340. + (NSError *)missingContinueURIErrorWithMessage:(nullable NSString *)message;
  341. /** @fn missingEmailErrorWithMessage
  342. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeMissingEmail code.
  343. @param message Error message from the backend, if any.
  344. @return The NSError instance associated with the given FIRAuthError.
  345. */
  346. + (NSError *)missingEmailErrorWithMessage:(nullable NSString *)message;
  347. /** @fn missingPhoneNumberErrorWithMessage:
  348. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeMissingPhoneNumber code.
  349. @param message Error message from the backend, if any.
  350. @return The NSError instance associated with the given FIRAuthError.
  351. */
  352. + (NSError *)missingPhoneNumberErrorWithMessage:(nullable NSString *)message;
  353. /** @fn invalidPhoneNumberErrorWithMessage:
  354. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeInvalidPhoneNumber code.
  355. @param message Error message from the backend, if any.
  356. @return The NSError instance associated with the given FIRAuthError.
  357. */
  358. + (NSError *)invalidPhoneNumberErrorWithMessage:(nullable NSString *)message;
  359. /** @fn missingVerificationCodeErrorWithMessage:
  360. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeMissingVerificationCode code.
  361. @param message Error message from the backend, if any.
  362. @return The NSError instance associated with the given FIRAuthError.
  363. */
  364. + (NSError *)missingVerificationCodeErrorWithMessage:(nullable NSString *)message;
  365. /** @fn invalidVerificationCodeErrorWithMessage:
  366. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeInvalidVerificationCode code.
  367. @param message Error message from the backend, if any.
  368. @return The NSError instance associated with the given FIRAuthError.
  369. */
  370. + (NSError *)invalidVerificationCodeErrorWithMessage:(nullable NSString *)message;
  371. /** @fn missingVerificationIDErrorWithMessage:
  372. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeMissingVerificationID code.
  373. @param message Error message from the backend, if any.
  374. @return The NSError instance associated with the given FIRAuthError.
  375. */
  376. + (NSError *)missingVerificationIDErrorWithMessage:(nullable NSString *)message;
  377. /** @fn invalidVerificationIDErrorWithMessage:
  378. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeInvalidVerificationID code.
  379. @param message Error message from the backend, if any.
  380. @return The NSError instance associated with the given FIRAuthError.
  381. */
  382. + (NSError *)invalidVerificationIDErrorWithMessage:(nullable NSString *)message;
  383. /** @fn sessionExpiredErrorWithMessage:
  384. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeSessionExpired code.
  385. @param message Error message from the backend, if any.
  386. @return The NSError instance associated with the given FIRAuthError.
  387. */
  388. + (NSError *)sessionExpiredErrorWithMessage:(nullable NSString *)message;
  389. /** @fn missingAppCredentialWithMessage:
  390. @brief Constructs an @c NSError with the @c FIRAuthErrorMissingCredential code.
  391. @param message Error message from the backend, if any.
  392. @return The NSError instance associated with the given FIRAuthError.
  393. */
  394. + (NSError *)missingAppCredentialWithMessage:(nullable NSString *)message;
  395. /** @fn invalidAppCredentialWithMessage:
  396. @brief Constructs an @c NSError with the @c FIRAuthErrorInvalidCredential code.
  397. @param message Error message from the backend, if any.
  398. @return The NSError instance associated with the given FIRAuthError.
  399. */
  400. + (NSError *)invalidAppCredentialWithMessage:(nullable NSString *)message;
  401. /** @fn quotaExceededErrorWithMessage:
  402. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeQuotaExceeded code.
  403. @param message Error message from the backend, if any.
  404. @return The NSError instance associated with the given FIRAuthError.
  405. */
  406. + (NSError *)quotaExceededErrorWithMessage:(nullable NSString *)message;
  407. /** @fn missingAppTokenErrorWithUnderlyingError
  408. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeMissingAppToken code.
  409. @param underlyingError The underlying error, if any.
  410. @return The NSError instance associated with the given FIRAuthError.
  411. */
  412. + (NSError *)missingAppTokenErrorWithUnderlyingError:(nullable NSError *)underlyingError;
  413. /** @fn localPlayerNotAuthenticatedError
  414. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeLocalPlayerNotAuthenticated code.
  415. @return The NSError instance associated with the given FIRAuthError.
  416. */
  417. + (NSError *)localPlayerNotAuthenticatedError;
  418. /** @fn gameKitNotLinkedError
  419. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeGameKitNotLinked code.
  420. @return The NSError instance associated with the given FIRAuthError.
  421. */
  422. + (NSError *)gameKitNotLinkedError;
  423. /** @fn notificationNotForwardedError
  424. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeNotificationNotForwarded code.
  425. @return The NSError instance associated with the given FIRAuthError.
  426. */
  427. + (NSError *)notificationNotForwardedError;
  428. #if TARGET_OS_IOS
  429. /** @fn secondFactorRequiredError
  430. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeSecondFactorRequired code.
  431. @return The NSError instance associated with the given FIRAuthError.
  432. */
  433. + (NSError *)
  434. secondFactorRequiredErrorWithPendingCredential:(NSString *)MFAPendingCredential
  435. hints:(NSArray<FIRMultiFactorInfo *> *)multiFactorInfo
  436. auth:(FIRAuth *)auth;
  437. #endif
  438. /** @fn appNotVerifiedErrorWithMessage:
  439. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeAppNotVerified code.
  440. @param message Error message from the backend, if any.
  441. @return The NSError instance associated with the given FIRAuthError.
  442. */
  443. + (NSError *)appNotVerifiedErrorWithMessage:(nullable NSString *)message;
  444. /** @fn missingClientIdentifierErrorWithMessage:
  445. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeMissingClientIdentifier code.
  446. @param message Error message from the backend, if any.
  447. @return The NSError instance associated with the given FIRAuthError.
  448. */
  449. + (NSError *)missingClientIdentifierErrorWithMessage:(nullable NSString *)message;
  450. /** @fn missingClientTypeErrorWithMessage:
  451. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeMissingClientType code.
  452. @param message Error message from the backend, if any.
  453. @return The NSError instance associated with the given FIRAuthError.
  454. */
  455. + (NSError *)missingClientTypeErrorWithMessage:(nullable NSString *)message;
  456. /** @fn captchaCheckFailedErrorWithMessage:
  457. @brief Constructs an @c NSError with the @c FIRAuthErrorCaptchaCheckFailed code.
  458. @param message Error message from the backend, if any.
  459. @return The NSError instance associated with the given FIRAuthError.
  460. */
  461. + (NSError *)captchaCheckFailedErrorWithMessage:(nullable NSString *)message;
  462. /** @fn webContextAlreadyPresentedErrorWithMessage:
  463. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeWebContextAlreadyPresented code.
  464. @param message Error message from the backend, if any.
  465. @return The NSError instance associated with the given FIRAuthError.
  466. */
  467. + (NSError *)webContextAlreadyPresentedErrorWithMessage:(nullable NSString *)message;
  468. /** @fn webContextCancelledErrorWithMessage:
  469. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeWebContextCancelled code.
  470. @param message Error message from the backend, if any.
  471. @return The NSError instance associated with the given FIRAuthError.
  472. */
  473. + (NSError *)webContextCancelledErrorWithMessage:(nullable NSString *)message;
  474. /** @fn appVerificationUserInteractionFailureWithReason:
  475. @brief Constructs an @c NSError with the @c
  476. FIRAuthErrorCodeAppVerificationUserInteractionFailure code.
  477. @param reason Reason for error, returned via URL response.
  478. @return The NSError instance associated with the given FIRAuthError.
  479. */
  480. + (NSError *)appVerificationUserInteractionFailureWithReason:(NSString *)reason;
  481. /** @fn webSignInUserInteractionFailureWithReason:
  482. @brief Constructs an @c NSError with the @c
  483. FIRAuthErrorCodeWebSignInUserInteractionFailure code.
  484. @param reason Reason for error, returned via URL response.
  485. @return The NSError instance associated with the given FIRAuthError.
  486. */
  487. + (NSError *)webSignInUserInteractionFailureWithReason:(nullable NSString *)reason;
  488. /** @fn URLResponseErrorWithCode:message:
  489. @brief Constructs an @c NSError with the code and message provided.
  490. @param message Error message from the backend, if any.
  491. @return The nullable NSError instance associated with the given error message, if one is found.
  492. */
  493. + (nullable NSError *)URLResponseErrorWithCode:(NSString *)code
  494. message:(nullable NSString *)message;
  495. /** @fn nullUserErrorWithMessage:
  496. @brief Constructs an @c NSError with the code and message provided.
  497. @param message Error message from the backend, if any.
  498. @return The nullable NSError instance associated with the given error message, if one is found.
  499. */
  500. + (NSError *)nullUserErrorWithMessage:(nullable NSString *)message;
  501. /** @fn invalidProviderIDErrorWithMessage:
  502. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeInvalidProviderID code.
  503. @param message Error message from the backend, if any.
  504. @remarks This error indicates that the provider id given for the web operation is invalid.
  505. */
  506. + (NSError *)invalidProviderIDErrorWithMessage:(nullable NSString *)message;
  507. /** @fn invalidDynamicLinkDomainErrorWithMessage:
  508. @brief Constructs an @c NSError with the code and message provided.
  509. @param message Error message from the backend, if any.
  510. @return The nullable NSError instance associated with the given error message, if one is found.
  511. */
  512. + (NSError *)invalidDynamicLinkDomainErrorWithMessage:(nullable NSString *)message;
  513. /** @fn keychainErrorWithFunction:status:
  514. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeKeychainError code.
  515. @param keychainFunction The keychain function which was invoked and yielded an unexpected
  516. response. The @c NSLocalizedFailureReasonErrorKey field in the @c NSError.userInfo
  517. dictionary will contain a string partially comprised of this value.
  518. @param status The response status from the invoked keychain function. The
  519. @c NSLocalizedFailureReasonErrorKey field in the @c NSError.userInfo dictionary will contain
  520. a string partially comprised of this value.
  521. */
  522. + (NSError *)keychainErrorWithFunction:(NSString *)keychainFunction status:(OSStatus)status;
  523. /** @fn missingOrInvalidNonceErrorWithMessage:
  524. @brief Constructs an @c NSError with the code and message provided.
  525. @param message Error message from the backend, if any.
  526. @return The nullable NSError instance associated with the given error message, if one is found.
  527. */
  528. + (NSError *)missingOrInvalidNonceErrorWithMessage:(nullable NSString *)message;
  529. /** @fn tenantIDMismatchError
  530. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeTenantIDMismatch code.
  531. @remarks This error is used when an attempt is made to update the current user with a
  532. tenantId that differs from the current FirebaseAuth instance's tenantId.
  533. */
  534. + (NSError *)tenantIDMismatchError;
  535. /** @fn unsupportedTenantOperationError
  536. @brief Constructs an @c NSError with the @c FIRUnsupportedTenantOperation code.
  537. @remarks This error indicates the operation is not supported in a multi-tenant context.
  538. */
  539. + (NSError *)unsupportedTenantOperationError;
  540. + (NSError *)blockingCloudFunctionServerResponseWithMessage:(nullable NSString *)message;
  541. /** @fn recaptchaSDKNotLinkedError
  542. @brief Constructs an @c NSError with the @c FIRAuthErrorCodeRecaptchaSDKNotLinked code.
  543. @return The NSError instance associated with the given FIRAuthError.
  544. */
  545. + (NSError *)recaptchaSDKNotLinkedError;
  546. @end
  547. NS_ASSUME_NONNULL_END