Skip to content

Commit

Permalink
misc: hopefully fix the return body
Browse files Browse the repository at this point in the history
when an update to the web UI fails because it somehow failed to use the
github api.
  • Loading branch information
revam committed Oct 30, 2023
1 parent d3de0f4 commit ec6ad41
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions Shoko.Server/API/v3/Controllers/WebUIController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Logging;
using Shoko.Server.API.Annotations;
using Shoko.Server.API.ModelBinders;
using Shoko.Server.API.v3.Helpers;
Expand Down Expand Up @@ -43,6 +44,9 @@ public class WebUIController : BaseController
});

private static readonly TimeSpan CacheTTL = TimeSpan.FromHours(1);

private readonly ILogger<WebUIController> _logger;

private readonly WebUIFactory _webUIFactory;

/// <summary>
Expand Down Expand Up @@ -306,7 +310,10 @@ public ActionResult InstallWebUI([FromQuery] ReleaseChannel channel = ReleaseCha
catch (WebException ex)
{
if (ex.Status != WebExceptionStatus.Success)
return StatusCode((int)HttpStatusCode.BadGateway, "Unable to use the GitHub API to check for an update. Check your connection.");
{
_logger.LogError(ex, "An error occured while trying to install the Web UI.");
return Problem("Unable to use the GitHub API to check for an update. Check your connection and try again.", null, (int)HttpStatusCode.BadGateway, "Unable to connect to GitHub.");
}
throw;
}

Expand Down Expand Up @@ -335,18 +342,21 @@ public ActionResult UpdateWebUI([FromQuery] ReleaseChannel channel = ReleaseChan
catch (WebException ex)
{
if (ex.Status != WebExceptionStatus.Success)
return StatusCode((int)HttpStatusCode.BadGateway, "Unable to use the GitHub API to check for an update. Check your connection.");
{
_logger.LogError(ex, "An error occured while trying to update the Web UI.");
return Problem("Unable to use the GitHub API to check for an update. Check your connection and try again.", null, (int)HttpStatusCode.BadGateway, "Unable to connect to GitHub.");
}
throw;
}

return NoContent();
}

/// <inheritdoc cref="UpdateWebUI"/>
[DatabaseBlockedExempt]
[InitFriendly]
[HttpGet("Update")]
[Obsolete("Post is correct, but we want old versions of the webui to be able to update. We can remove this later")]
[Obsolete("Post is correct, but we want old versions of the webui to be able to update. We can remove this later™.")]
public ActionResult UpdateWebUIOld([FromQuery] ReleaseChannel channel = ReleaseChannel.Stable)
{
return UpdateWebUI(channel);
Expand Down Expand Up @@ -564,8 +574,9 @@ public ActionResult<ComponentVersion> LatestServerWebUIVersion([FromQuery] Relea
}


public WebUIController(ISettingsProvider settingsProvider, WebUIFactory webUIFactory) : base(settingsProvider)
public WebUIController(ISettingsProvider settingsProvider, WebUIFactory webUIFactory, ILogger<WebUIController> logger) : base(settingsProvider)
{
_logger = logger;
_webUIFactory = webUIFactory;
}
}

0 comments on commit ec6ad41

Please sign in to comment.