From 112cc652dee412d356591628b95af3ffebdb0a7a Mon Sep 17 00:00:00 2001 From: JT Date: Thu, 8 Feb 2024 18:01:11 -0800 Subject: [PATCH] Fix crash on recommended models dialog when civitai ded --- .../Dialogs/RecommendedModelsViewModel.cs | 44 ++++++++++++------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/StabilityMatrix.Avalonia/ViewModels/Dialogs/RecommendedModelsViewModel.cs b/StabilityMatrix.Avalonia/ViewModels/Dialogs/RecommendedModelsViewModel.cs index 3ae964a4..41750364 100644 --- a/StabilityMatrix.Avalonia/ViewModels/Dialogs/RecommendedModelsViewModel.cs +++ b/StabilityMatrix.Avalonia/ViewModels/Dialogs/RecommendedModelsViewModel.cs @@ -8,6 +8,7 @@ using CommunityToolkit.Mvvm.Input; using DynamicData; using DynamicData.Binding; using Microsoft.Extensions.Logging; +using Refit; using StabilityMatrix.Avalonia.Services; using StabilityMatrix.Avalonia.ViewModels.Base; using StabilityMatrix.Core.Api; @@ -86,21 +87,34 @@ public partial class RecommendedModelsViewModel : ContentDialogViewModelBase IsLoading = true; - var recommendedModels = await lykosApi.GetRecommendedModels(); - - CivitModels.AddOrUpdate( - recommendedModels.Items.Select( - model => - new RecommendedModelItemViewModel - { - ModelVersion = model.ModelVersions.First( - x => !x.BaseModel.Contains("Turbo", StringComparison.OrdinalIgnoreCase) - ), - Author = $"by {model.Creator.Username}", - CivitModel = model - } - ) - ); + try + { + var recommendedModels = await lykosApi.GetRecommendedModels(); + + CivitModels.AddOrUpdate( + recommendedModels.Items.Select( + model => + new RecommendedModelItemViewModel + { + ModelVersion = model.ModelVersions.First( + x => !x.BaseModel.Contains("Turbo", StringComparison.OrdinalIgnoreCase) + ), + Author = $"by {model.Creator.Username}", + CivitModel = model + } + ) + ); + } + catch (ApiException e) + { + // hide dialog and show error msg + logger.LogError(e, "Failed to get recommended models"); + notificationService.Show( + "Failed to get recommended models", + "Please try again later or check the Model Browser tab for more models." + ); + OnCloseButtonClick(); + } IsLoading = false; }