mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-15 02:00:09 +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 BotConfig _config;
|
||||||
private readonly HttpClient _client;
|
private readonly HttpClient _client;
|
||||||
|
|
||||||
public AvatarHostingService(BotConfig config, HttpClient client)
|
public AvatarHostingService(BotConfig config)
|
||||||
{
|
{
|
||||||
_config = 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)
|
public async Task<ParsedImage> TryRehostImage(ParsedImage input, RehostedImageType type, ulong userId, PKSystem? system)
|
||||||
{
|
{
|
||||||
var uploaded = await TryUploadAvatar(input.Url, type, userId, system);
|
try
|
||||||
if (uploaded != null)
|
|
||||||
{
|
{
|
||||||
// todo: make new image type called Cdn?
|
var uploaded = await TryUploadAvatar(input.Url, type, userId, system);
|
||||||
return new ParsedImage { Url = uploaded, Source = AvatarSource.HostedCdn };
|
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)
|
public async Task<string?> TryUploadAvatar(string? avatarUrl, RehostedImageType type, ulong userId, PKSystem? system)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue