diff --git a/CHANGELOG.md b/CHANGELOG.md index f6cd7283..b3a8dcbd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed + +- Print error information about HTTP 401 instead of "Unable to determine". + ## [5.4.1] - 2023-09-12 ### Fixed diff --git a/src/Recyclarr.Cli/Processors/ErrorHandling/FlurlHttpExceptionHandler.cs b/src/Recyclarr.Cli/Processors/ErrorHandling/FlurlHttpExceptionHandler.cs index 32dc16ab..294ff1ff 100644 --- a/src/Recyclarr.Cli/Processors/ErrorHandling/FlurlHttpExceptionHandler.cs +++ b/src/Recyclarr.Cli/Processors/ErrorHandling/FlurlHttpExceptionHandler.cs @@ -15,12 +15,27 @@ public class FlurlHttpExceptionHandler : IFlurlHttpExceptionHandler [SuppressMessage("Design", "CA1031:Do not catch general exception types")] public async Task ProcessServiceErrorMessages(IServiceErrorMessageExtractor extractor) { - var responseBody = await extractor.GetErrorMessage(); + var statusCode = extractor.GetHttpStatusCode(); + + switch (statusCode) + { + case 401: + _log.Error("Reason: Recyclarr is unauthorized to talk to the service. Is your `api_key` correct?"); + break; + + default: + ProcessBody(await extractor.GetErrorMessage()); + break; + } + } + + private void ProcessBody(string responseBody) + { var parser = new ErrorResponseParser(_log, responseBody); if (parser.DeserializeList(s => s - .Select(x => (string) x.errorMessage) - .NotNull(x => !string.IsNullOrEmpty(x)))) + .Select(x => (string) x.errorMessage) + .NotNull(x => !string.IsNullOrEmpty(x)))) { return; } diff --git a/src/Recyclarr.Cli/Processors/ErrorHandling/IServiceErrorMessageExtractor.cs b/src/Recyclarr.Cli/Processors/ErrorHandling/IServiceErrorMessageExtractor.cs index bd8ca351..ff865e95 100644 --- a/src/Recyclarr.Cli/Processors/ErrorHandling/IServiceErrorMessageExtractor.cs +++ b/src/Recyclarr.Cli/Processors/ErrorHandling/IServiceErrorMessageExtractor.cs @@ -3,4 +3,5 @@ namespace Recyclarr.Cli.Processors.ErrorHandling; public interface IServiceErrorMessageExtractor { Task GetErrorMessage(); + int? GetHttpStatusCode(); } diff --git a/src/Recyclarr.Cli/Processors/ErrorHandling/ServiceErrorMessageExtractor.cs b/src/Recyclarr.Cli/Processors/ErrorHandling/ServiceErrorMessageExtractor.cs index df8fdc8d..36247146 100644 --- a/src/Recyclarr.Cli/Processors/ErrorHandling/ServiceErrorMessageExtractor.cs +++ b/src/Recyclarr.Cli/Processors/ErrorHandling/ServiceErrorMessageExtractor.cs @@ -15,4 +15,9 @@ public class ServiceErrorMessageExtractor : IServiceErrorMessageExtractor { return await _e.GetResponseStringAsync(); } + + public int? GetHttpStatusCode() + { + return _e.StatusCode; + } }