diff --git a/CHANGELOG.md b/CHANGELOG.md index 951213f2..e6bbdb98 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 instead of `~/.config/recyclarr`. Recyclarr will attempt to move this directory when run. If it can't, then manual intervention is needed by users (e.g. `recyclarr migrate`). +### Fixed + +- Print more useful diagnostics when there's a connectivity problem to a service (e.g. incorrect + `base_url`). + ## [6.0.2] - 2023-10-20 ### Fixed diff --git a/src/Recyclarr.Cli/Processors/ErrorHandling/FlurlHttpExceptionHandler.cs b/src/Recyclarr.Cli/Processors/ErrorHandling/FlurlHttpExceptionHandler.cs index 2775edc7..5e60e046 100644 --- a/src/Recyclarr.Cli/Processors/ErrorHandling/FlurlHttpExceptionHandler.cs +++ b/src/Recyclarr.Cli/Processors/ErrorHandling/FlurlHttpExceptionHandler.cs @@ -8,14 +8,16 @@ public class FlurlHttpExceptionHandler(ILogger log) : IFlurlHttpExceptionHandler [SuppressMessage("Design", "CA1031:Do not catch general exception types")] public async Task ProcessServiceErrorMessages(IServiceErrorMessageExtractor extractor) { - var statusCode = extractor.GetHttpStatusCode(); - - switch (statusCode) + switch (extractor) { - case 401: + case {HttpStatusCode: 401}: log.Error("Reason: Recyclarr is unauthorized to talk to the service. Is your `api_key` correct?"); break; + case {HttpStatusCode: null}: + log.Error("Reason: Problem connecting to service. Is your `base_url` correct?"); + break; + default: ProcessBody(await extractor.GetErrorMessage()); break; @@ -47,6 +49,7 @@ public class FlurlHttpExceptionHandler(ILogger log) : IFlurlHttpExceptionHandler } // Last resort - log.Error("Reason: Unable to determine. Please report this as a bug and attach your `verbose.log` file."); + log.Error( + "Reason: Unable to determine. Please report this as a bug and attach your `debug.log` and `verbose.log` files."); } } diff --git a/src/Recyclarr.Cli/Processors/ErrorHandling/IServiceErrorMessageExtractor.cs b/src/Recyclarr.Cli/Processors/ErrorHandling/IServiceErrorMessageExtractor.cs index ff865e95..1248ddaa 100644 --- a/src/Recyclarr.Cli/Processors/ErrorHandling/IServiceErrorMessageExtractor.cs +++ b/src/Recyclarr.Cli/Processors/ErrorHandling/IServiceErrorMessageExtractor.cs @@ -3,5 +3,6 @@ namespace Recyclarr.Cli.Processors.ErrorHandling; public interface IServiceErrorMessageExtractor { Task GetErrorMessage(); - int? GetHttpStatusCode(); + int? HttpStatusCode { get; } + HttpRequestError? HttpError { get; } } diff --git a/src/Recyclarr.Cli/Processors/ErrorHandling/ServiceErrorMessageExtractor.cs b/src/Recyclarr.Cli/Processors/ErrorHandling/ServiceErrorMessageExtractor.cs index 46d848b2..febb9c8a 100644 --- a/src/Recyclarr.Cli/Processors/ErrorHandling/ServiceErrorMessageExtractor.cs +++ b/src/Recyclarr.Cli/Processors/ErrorHandling/ServiceErrorMessageExtractor.cs @@ -4,13 +4,23 @@ namespace Recyclarr.Cli.Processors.ErrorHandling; public class ServiceErrorMessageExtractor(FlurlHttpException e) : IServiceErrorMessageExtractor { - public async Task GetErrorMessage() + public HttpRequestError? HttpError { - return await e.GetResponseStringAsync(); + get + { + if (e.InnerException is not HttpRequestException http) + { + return null; + } + + return http.HttpRequestError; + } } - public int? GetHttpStatusCode() + public async Task GetErrorMessage() { - return e.StatusCode; + return await e.GetResponseStringAsync(); } + + public int? HttpStatusCode => e.StatusCode; }