From 3b9065061cddaefd0d265e1f4c7e00bc248666b2 Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Wed, 19 Sep 2018 14:50:47 -0400 Subject: [PATCH] Return failed dependency when random GitHub API exceptions occur --- docs/API.dox | 1 + .../Controllers/AdministrationController.cs | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/docs/API.dox b/docs/API.dox index c05ca4243d..79ca621469 100644 --- a/docs/API.dox +++ b/docs/API.dox @@ -62,6 +62,7 @@ TGS will only every return the response codes listed here - 409: Conflict. Documented in the requests that use them - 410: Gone. Attempted to access/modify a resource that ideally should have been ready, but isn't or no longer is - 422: Unprocessable Entity: Used specifically when an operation that requires a server restart is unable to be performed due to the @ref Tgstation.Server.Host.Watchdog not being present in the deployment. Blame MSO. Response body contains an @ref Tgstation.Server.Api.Models.ErrorMessage +- 424: Failed Dependency: When a request that depends on the GitHub API fails for a reason other than rate limiting. Check server logs, usually this indicates a bad access token. - 426: Upgrade required: Used when the client's API version is not compatible with the server's. Response body contains an @ref Tgstation.Server.Api.Models.ErrorMessage - 429: Rate limited. Used with operations that rely on GitHub.com. If a rate limit is hit for an operation this will be returned. Response will contain a Retry-After header - 500: Server error. Please report the request and response body to the code repository diff --git a/src/Tgstation.Server.Host/Controllers/AdministrationController.cs b/src/Tgstation.Server.Host/Controllers/AdministrationController.cs index e3d8fb5e6a..553163da07 100644 --- a/src/Tgstation.Server.Host/Controllers/AdministrationController.cs +++ b/src/Tgstation.Server.Host/Controllers/AdministrationController.cs @@ -30,6 +30,8 @@ namespace Tgstation.Server.Host.Controllers { const string RestartNotSupportedException = "This deployment of tgstation-server is lacking the Tgstation.Server.Host.Watchdog component. Restarts and version changes cannot be completed!"; + const string OctokitException = "Bad GitHub API response, check configuration! Exception: {0}"; + /// /// The for the /// @@ -128,6 +130,11 @@ namespace Tgstation.Server.Host.Controllers { return RateLimit(e); } + catch (ApiException e) + { + Logger.LogWarning(OctokitException, e); + return StatusCode((int)HttpStatusCode.FailedDependency); + } } /// @@ -154,6 +161,11 @@ namespace Tgstation.Server.Host.Controllers { return RateLimit(e); } + catch (ApiException e) + { + Logger.LogWarning(OctokitException, e); + return StatusCode((int)HttpStatusCode.FailedDependency); + } Logger.LogTrace("Release query complete!"); foreach (var release in releases)