Skip to content

Commit e7ea997

Browse files
committed
More error codes, tests and documentation
1 parent dd991f9 commit e7ea997

File tree

4 files changed

+56
-12
lines changed

4 files changed

+56
-12
lines changed

FirebaseAdmin/FirebaseAdmin.Tests/Auth/AuthErrorHandlerTest.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,30 @@ public class AuthErrorHandlerTest
2525
public static readonly IEnumerable<object[]> AuthErrorCodes =
2626
new List<object[]>()
2727
{
28+
new object[]
29+
{
30+
"DUPLICATE_EMAIL",
31+
ErrorCode.AlreadyExists,
32+
AuthErrorCode.EmailAlreadyExists,
33+
},
2834
new object[]
2935
{
3036
"DUPLICATE_LOCAL_ID",
3137
ErrorCode.AlreadyExists,
3238
AuthErrorCode.UidAlreadyExists,
3339
},
40+
new object[]
41+
{
42+
"PHONE_NUMBER_EXISTS",
43+
ErrorCode.AlreadyExists,
44+
AuthErrorCode.PhoneNumberAlreadyExists,
45+
},
46+
new object[]
47+
{
48+
"USER_NOT_FOUND",
49+
ErrorCode.NotFound,
50+
AuthErrorCode.UserNotFound,
51+
},
3452
};
3553

3654
[Theory]

FirebaseAdmin/FirebaseAdmin/Auth/AuthErrorCode.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@ namespace FirebaseAdmin.Auth
1919
/// </summary>
2020
public enum AuthErrorCode
2121
{
22+
/// <summary>
23+
/// The user with the provided email already exists.
24+
/// </summary>
25+
EmailAlreadyExists,
26+
27+
/// <summary>
28+
/// The user with the provided phone number already exists.
29+
/// </summary>
30+
PhoneNumberAlreadyExists,
31+
2232
/// <summary>
2333
/// The user with the provided uid already exists.
2434
/// </summary>

FirebaseAdmin/FirebaseAdmin/Auth/AuthErrorHandler.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,27 @@ internal sealed class AuthErrorHandler : HttpErrorHandler
3030
private static readonly IReadOnlyDictionary<string, ErrorInfo> CodeToErrorInfo =
3131
new Dictionary<string, ErrorInfo>()
3232
{
33+
{
34+
"DUPLICATE_EMAIL",
35+
new ErrorInfo(
36+
ErrorCode.AlreadyExists,
37+
AuthErrorCode.EmailAlreadyExists,
38+
"The user with the provided email already exists")
39+
},
3340
{
3441
"DUPLICATE_LOCAL_ID",
3542
new ErrorInfo(
3643
ErrorCode.AlreadyExists,
3744
AuthErrorCode.UidAlreadyExists,
3845
"The user with the provided uid already exists")
3946
},
47+
{
48+
"PHONE_NUMBER_EXISTS",
49+
new ErrorInfo(
50+
ErrorCode.AlreadyExists,
51+
AuthErrorCode.PhoneNumberAlreadyExists,
52+
"The user with the provided phone number already exists")
53+
},
4054
{
4155
"USER_NOT_FOUND",
4256
new ErrorInfo(

FirebaseAdmin/FirebaseAdmin/Auth/FirebaseAuth.cs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ public async Task<FirebaseToken> VerifyIdTokenAsync(
269269
/// the newly created user account.</returns>
270270
/// <exception cref="ArgumentNullException">If <paramref name="args"/> is null.</exception>
271271
/// <exception cref="ArgumentException">If any of the values in <paramref name="args"/> are invalid.</exception>
272-
/// <exception cref="FirebaseException">If an error occurs while creating the user account.</exception>
272+
/// <exception cref="FirebaseAuthException">If an error occurs while creating the user account.</exception>
273273
public async Task<UserRecord> CreateUserAsync(UserRecordArgs args)
274274
{
275275
return await this.CreateUserAsync(args, default(CancellationToken))
@@ -286,7 +286,7 @@ public async Task<UserRecord> CreateUserAsync(UserRecordArgs args)
286286
/// the newly created user account.</returns>
287287
/// <exception cref="ArgumentNullException">If <paramref name="args"/> is null.</exception>
288288
/// <exception cref="ArgumentException">If any of the values in <paramref name="args"/> are invalid.</exception>
289-
/// <exception cref="FirebaseException">If an error occurs while creating the user account.</exception>
289+
/// <exception cref="FirebaseAuthException">If an error occurs while creating the user account.</exception>
290290
public async Task<UserRecord> CreateUserAsync(
291291
UserRecordArgs args, CancellationToken cancellationToken)
292292
{
@@ -304,7 +304,7 @@ public async Task<UserRecord> CreateUserAsync(
304304
/// <returns>A task that completes with a <see cref="UserRecord"/> representing
305305
/// a user with the specified user ID.</returns>
306306
/// <exception cref="ArgumentException">If user ID argument is null or empty.</exception>
307-
/// <exception cref="FirebaseException">If a user cannot be found with the specified user ID.</exception>
307+
/// <exception cref="FirebaseAuthException">If a user cannot be found with the specified user ID.</exception>
308308
public async Task<UserRecord> GetUserAsync(string uid)
309309
{
310310
return await this.GetUserAsync(uid, default(CancellationToken))
@@ -321,7 +321,7 @@ public async Task<UserRecord> GetUserAsync(string uid)
321321
/// <returns>A task that completes with a <see cref="UserRecord"/> representing
322322
/// a user with the specified user ID.</returns>
323323
/// <exception cref="ArgumentException">If user ID argument is null or empty.</exception>
324-
/// <exception cref="FirebaseException">If a user cannot be found with the specified user ID.</exception>
324+
/// <exception cref="FirebaseAuthException">If a user cannot be found with the specified user ID.</exception>
325325
public async Task<UserRecord> GetUserAsync(
326326
string uid, CancellationToken cancellationToken)
327327
{
@@ -339,7 +339,7 @@ public async Task<UserRecord> GetUserAsync(
339339
/// <returns>A task that completes with a <see cref="UserRecord"/> representing
340340
/// a user with the specified email.</returns>
341341
/// <exception cref="ArgumentException">If the email argument is null or empty.</exception>
342-
/// <exception cref="FirebaseException">If a user cannot be found with the specified email.</exception>
342+
/// <exception cref="FirebaseAuthException">If a user cannot be found with the specified email.</exception>
343343
public async Task<UserRecord> GetUserByEmailAsync(string email)
344344
{
345345
return await this.GetUserByEmailAsync(email, default(CancellationToken))
@@ -356,7 +356,7 @@ public async Task<UserRecord> GetUserByEmailAsync(string email)
356356
/// <returns>A task that completes with a <see cref="UserRecord"/> representing
357357
/// a user with the specified email.</returns>
358358
/// <exception cref="ArgumentException">If the email argument is null or empty.</exception>
359-
/// <exception cref="FirebaseException">If a user cannot be found with the specified email.</exception>
359+
/// <exception cref="FirebaseAuthException">If a user cannot be found with the specified email.</exception>
360360
public async Task<UserRecord> GetUserByEmailAsync(
361361
string email, CancellationToken cancellationToken)
362362
{
@@ -374,7 +374,7 @@ public async Task<UserRecord> GetUserByEmailAsync(
374374
/// <returns>A task that completes with a <see cref="UserRecord"/> representing
375375
/// a user with the specified phone number.</returns>
376376
/// <exception cref="ArgumentException">If the phone number argument is null or empty.</exception>
377-
/// <exception cref="FirebaseException">If a user cannot be found with the specified phone number.</exception>
377+
/// <exception cref="FirebaseAuthException">If a user cannot be found with the specified phone number.</exception>
378378
public async Task<UserRecord> GetUserByPhoneNumberAsync(string phoneNumber)
379379
{
380380
return await this.GetUserByPhoneNumberAsync(phoneNumber, default(CancellationToken))
@@ -391,7 +391,7 @@ public async Task<UserRecord> GetUserByPhoneNumberAsync(string phoneNumber)
391391
/// <returns>A task that completes with a <see cref="UserRecord"/> representing
392392
/// a user with the specified phone number.</returns>
393393
/// <exception cref="ArgumentException">If the phone number argument is null or empty.</exception>
394-
/// <exception cref="FirebaseException">If a user cannot be found with the specified phone number.</exception>
394+
/// <exception cref="FirebaseAuthException">If a user cannot be found with the specified phone number.</exception>
395395
public async Task<UserRecord> GetUserByPhoneNumberAsync(
396396
string phoneNumber, CancellationToken cancellationToken)
397397
{
@@ -410,7 +410,7 @@ public async Task<UserRecord> GetUserByPhoneNumberAsync(
410410
/// the updated user account.</returns>
411411
/// <exception cref="ArgumentNullException">If <paramref name="args"/> is null.</exception>
412412
/// <exception cref="ArgumentException">If any of the values in <paramref name="args"/> are invalid.</exception>
413-
/// <exception cref="FirebaseException">If an error occurs while updating the user account.</exception>
413+
/// <exception cref="FirebaseAuthException">If an error occurs while updating the user account.</exception>
414414
public async Task<UserRecord> UpdateUserAsync(UserRecordArgs args)
415415
{
416416
return await this.UpdateUserAsync(args, default(CancellationToken))
@@ -428,7 +428,7 @@ public async Task<UserRecord> UpdateUserAsync(UserRecordArgs args)
428428
/// the updated user account.</returns>
429429
/// <exception cref="ArgumentNullException">If <paramref name="args"/> is null.</exception>
430430
/// <exception cref="ArgumentException">If any of the values in <paramref name="args"/> are invalid.</exception>
431-
/// <exception cref="FirebaseException">If an error occurs while updating the user account.</exception>
431+
/// <exception cref="FirebaseAuthException">If an error occurs while updating the user account.</exception>
432432
public async Task<UserRecord> UpdateUserAsync(
433433
UserRecordArgs args, CancellationToken cancellationToken)
434434
{
@@ -445,7 +445,7 @@ public async Task<UserRecord> UpdateUserAsync(
445445
/// <param name="uid">A user ID string.</param>
446446
/// <returns>A task that completes when the user account has been deleted.</returns>
447447
/// <exception cref="ArgumentException">If the user ID argument is null or empty.</exception>
448-
/// <exception cref="FirebaseException">If an error occurs while deleting the user.</exception>
448+
/// <exception cref="FirebaseAuthException">If an error occurs while deleting the user.</exception>
449449
public async Task DeleteUserAsync(string uid)
450450
{
451451
await this.DeleteUserAsync(uid, default(CancellationToken))
@@ -460,7 +460,7 @@ public async Task DeleteUserAsync(string uid)
460460
/// operation.</param>
461461
/// <returns>A task that completes when the user account has been deleted.</returns>
462462
/// <exception cref="ArgumentException">If the user ID argument is null or empty.</exception>
463-
/// <exception cref="FirebaseException">If an error occurs while deleting the user.</exception>
463+
/// <exception cref="FirebaseAuthException">If an error occurs while deleting the user.</exception>
464464
public async Task DeleteUserAsync(string uid, CancellationToken cancellationToken)
465465
{
466466
var userManager = this.IfNotDeleted(() => this.userManager.Value);
@@ -478,6 +478,7 @@ await userManager.DeleteUserAsync(uid, cancellationToken)
478478
/// <exception cref="ArgumentException">If <paramref name="uid"/> is null, empty or longer
479479
/// than 128 characters. Or, if the serialized <paramref name="claims"/> is larger than 1000
480480
/// characters.</exception>
481+
/// <exception cref="FirebaseAuthException">If an error occurs while setting custom claims.</exception>
481482
/// <param name="uid">The user ID string for the custom claims will be set. Must not be null
482483
/// or longer than 128 characters.
483484
/// </param>
@@ -500,6 +501,7 @@ public async Task SetCustomUserClaimsAsync(
500501
/// <exception cref="ArgumentException">If <paramref name="uid"/> is null, empty or longer
501502
/// than 128 characters. Or, if the serialized <paramref name="claims"/> is larger than 1000
502503
/// characters.</exception>
504+
/// <exception cref="FirebaseAuthException">If an error occurs while setting custom claims.</exception>
503505
/// <param name="uid">The user ID string for the custom claims will be set. Must not be null
504506
/// or longer than 128 characters.
505507
/// </param>

0 commit comments

Comments
 (0)