[frontend/services] Display error and return empty list without changing state when failing to get emojis

This commit is contained in:
pancakes 2025-03-27 01:15:20 +10:00
parent b79de70345
commit 1c7f2832a1
No known key found for this signature in database

View file

@ -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 [];
}
}
}