fix: Print information about HTTP 401

json-serializing-nullable-fields-issue
Robert Dailey 8 months ago
parent 1411eb69bc
commit 58b59c4a62

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

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

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

@ -15,4 +15,9 @@ public class ServiceErrorMessageExtractor : IServiceErrorMessageExtractor
{
return await _e.GetResponseStringAsync();
}
public int? GetHttpStatusCode()
{
return _e.StatusCode;
}
}

Loading…
Cancel
Save