fix: Better diagnostics for connectivity issues

pull/231/head
Robert Dailey 11 months ago
parent 29c75549fb
commit 1ab44f974c

@ -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

@ -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.");
}
}

@ -3,5 +3,6 @@ namespace Recyclarr.Cli.Processors.ErrorHandling;
public interface IServiceErrorMessageExtractor
{
Task<string> GetErrorMessage();
int? GetHttpStatusCode();
int? HttpStatusCode { get; }
HttpRequestError? HttpError { get; }
}

@ -4,13 +4,23 @@ namespace Recyclarr.Cli.Processors.ErrorHandling;
public class ServiceErrorMessageExtractor(FlurlHttpException e) : IServiceErrorMessageExtractor
{
public async Task<string> 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<string> GetErrorMessage()
{
return e.StatusCode;
return await e.GetResponseStringAsync();
}
public int? HttpStatusCode => e.StatusCode;
}

Loading…
Cancel
Save