mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-06 22:07:55 +00:00
fix(bot): bump avatar service http timeout, add better user-facing error
This commit is contained in:
parent
17f5561293
commit
2152953b4b
1 changed files with 21 additions and 8 deletions
|
|
@ -9,22 +9,35 @@ public class AvatarHostingService
|
|||
private readonly BotConfig _config;
|
||||
private readonly HttpClient _client;
|
||||
|
||||
public AvatarHostingService(BotConfig config, HttpClient client)
|
||||
public AvatarHostingService(BotConfig config)
|
||||
{
|
||||
_config = config;
|
||||
_client = client;
|
||||
_client = new HttpClient
|
||||
{
|
||||
Timeout = TimeSpan.FromSeconds(10),
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<ParsedImage> TryRehostImage(ParsedImage input, RehostedImageType type, ulong userId, PKSystem? system)
|
||||
{
|
||||
var uploaded = await TryUploadAvatar(input.Url, type, userId, system);
|
||||
if (uploaded != null)
|
||||
try
|
||||
{
|
||||
// todo: make new image type called Cdn?
|
||||
return new ParsedImage { Url = uploaded, Source = AvatarSource.HostedCdn };
|
||||
}
|
||||
var uploaded = await TryUploadAvatar(input.Url, type, userId, system);
|
||||
if (uploaded != null)
|
||||
{
|
||||
// todo: make new image type called Cdn?
|
||||
return new ParsedImage { Url = uploaded, Source = AvatarSource.HostedCdn };
|
||||
}
|
||||
|
||||
return input;
|
||||
return input;
|
||||
}
|
||||
catch (TaskCanceledException e)
|
||||
{
|
||||
// don't show an internal error to users
|
||||
if (e.Message.Contains("HttpClient.Timeout"))
|
||||
throw new PKError("Temporary error setting image, please try again later");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<string?> TryUploadAvatar(string? avatarUrl, RehostedImageType type, ulong userId, PKSystem? system)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue