Skip to content

Commit a79c812

Browse files
Improve error handling for member retrieval in forums API calls and add cancellation token support
1 parent 9527c94 commit a79c812

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

src/XtremeIdiots.Portal.Integrations.Forums/AdminActionTopics.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public async Task<int> CreateTopicForAdminAction(AdminActionType type, GameType
4545
_ => 28
4646
};
4747

48-
var postTopicResult = await forumsClient.Forums.PostTopic(forumId, userId, $"{username} - {type}", PostContent(type, playerId, username, created, text), type.ToString()).ConfigureAwait(false);
48+
var postTopicResult = await forumsClient.Forums.PostTopic(forumId, userId, $"{username} - {type}", PostContent(type, playerId, username, created, text), type.ToString(), cancellationToken).ConfigureAwait(false);
4949

5050
if (postTopicResult?.Result?.Data is null)
5151
{
@@ -88,7 +88,7 @@ public async Task UpdateTopicForAdminAction(int topicId, AdminActionType type, G
8888
if (adminId is not null)
8989
userId = Convert.ToInt32(adminId);
9090

91-
await forumsClient.Forums.UpdateTopic(topicId, userId, PostContent(type, playerId, username, created, text)).ConfigureAwait(false);
91+
await forumsClient.Forums.UpdateTopic(topicId, userId, PostContent(type, playerId, username, created, text), cancellationToken).ConfigureAwait(false);
9292
}
9393

9494
private static string PostContent(AdminActionType type, Guid playerId, string username, DateTime created, string text)

src/XtremeIdiots.Portal.Web/Auth/XtremeIdiots/XtremeIdiotsAuth.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,13 @@ private async Task UpdateExistingUser(ExternalLoginInfo info, CancellationToken
7575
cancellationToken.ThrowIfCancellationRequested();
7676

7777
var memberResult = await forumsClient.Core.GetMember(id, cancellationToken).ConfigureAwait(false);
78-
var member = memberResult?.Result?.Data ?? throw new InvalidOperationException($"Member not found with ID: {id}");
78+
79+
if (memberResult is null || !memberResult.IsSuccess)
80+
{
81+
throw new InvalidOperationException($"Forums API call failed for member ID: {id} with status: {memberResult?.StatusCode.ToString() ?? "null response"}");
82+
}
83+
84+
var member = memberResult.Result?.Data ?? throw new InvalidOperationException($"Member not found with ID: {id}");
7985
var user = await userManager.FindByLoginAsync(info.LoginProvider, info.ProviderKey).ConfigureAwait(false) ?? throw new InvalidOperationException($"User not found for login provider: {info.LoginProvider}, key: {info.ProviderKey}");
8086
cancellationToken.ThrowIfCancellationRequested();
8187

@@ -128,7 +134,13 @@ private async Task RegisterNewUser(ExternalLoginInfo info, CancellationToken can
128134
cancellationToken.ThrowIfCancellationRequested();
129135

130136
var memberResult = await forumsClient.Core.GetMember(id, cancellationToken).ConfigureAwait(false);
131-
var member = memberResult?.Result?.Data ?? throw new InvalidOperationException($"Member not found with ID: {id}");
137+
138+
if (memberResult is null || !memberResult.IsSuccess)
139+
{
140+
throw new InvalidOperationException($"Forums API call failed for member ID: {id} with status: {memberResult?.StatusCode.ToString() ?? "null response"}");
141+
}
142+
143+
var member = memberResult.Result?.Data ?? throw new InvalidOperationException($"Member not found with ID: {id}");
132144
var user = new IdentityUser { Id = id, UserName = username, Email = email };
133145
var createUserResult = await userManager.CreateAsync(user).ConfigureAwait(false);
134146

0 commit comments

Comments
 (0)