[frontend/services] Display error and return empty list without changing state when failing to get emojis
This commit is contained in:
parent
b79de70345
commit
1c7f2832a1
1 changed files with 14 additions and 4 deletions
|
@ -1,12 +1,15 @@
|
|||
using System.Text.Json;
|
||||
using Iceshrimp.Frontend.Components;
|
||||
using Iceshrimp.Frontend.Core.Miscellaneous;
|
||||
using Iceshrimp.Shared.Schemas.Web;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
|
||||
namespace Iceshrimp.Frontend.Core.Services;
|
||||
|
||||
internal class EmojiService(ApiService api)
|
||||
internal class EmojiService(ApiService api, GlobalComponentSvc global)
|
||||
{
|
||||
[Inject] private ApiService Api { get; set; } = api;
|
||||
[Inject] private GlobalComponentSvc Global { get; set; } = global;
|
||||
private List<EmojiResponse>? Emojis { get; set; }
|
||||
|
||||
public async Task<List<EmojiResponse>> GetEmojiAsync()
|
||||
|
@ -18,10 +21,17 @@ internal class EmojiService(ApiService api)
|
|||
Emojis = emoji;
|
||||
return Emojis;
|
||||
}
|
||||
catch (ApiException)
|
||||
catch (ApiException e)
|
||||
{
|
||||
// FIXME: Implement connection error handling
|
||||
throw new Exception("Failed to fetch emoji");
|
||||
await Global.NoticeDialog?.Display(e.Response.Message ?? "Unable to load emojis",
|
||||
NoticeDialog.NoticeType.Error)!;
|
||||
return [];
|
||||
}
|
||||
catch (JsonException)
|
||||
{
|
||||
await Global.NoticeDialog?.Display("Emojis provided by the server didn't match what the client expected",
|
||||
NoticeDialog.NoticeType.Error)!;
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue