fix(protocol): report Chronos's own info error as that error, not a disposed stream
The identity check reads Chronos's error body to tell it from another service; GetInfoAsync then read it again and threw ObjectDisposedException. The identity now carries the parsed error and GetInfoAsync throws it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
0aa2fb8135
commit
2585b5d45f
2 files changed
+33
-4
No files matched your search
@@ -97,7 +97,8 @@ public sealed class ChronosClient : IDisposable
|
||||
var answer = await IdentifyAsync(response, ct).ConfigureAwait(false);
|
||||
if (answer.Info is { } info) return info;
|
||||
if (answer.Chronos == false) throw new NotChronosServerException(BaseAddress);
|
||||
// Chronos's own error, or busy: as any other request reports it.
|
||||
// Chronos's own error, already read (the body cannot be read twice), or busy: as any other request reports it.
|
||||
if (answer.Error is { } error) throw new ChronosApiException(response.StatusCode, error);
|
||||
await EnsureSuccessAsync(response, ct).ConfigureAwait(false);
|
||||
throw new NotChronosServerException(BaseAddress);
|
||||
}
|
||||
@@ -112,8 +113,11 @@ public sealed class ChronosClient : IDisposable
|
||||
private static bool IsChronos(ServerInfo? info) =>
|
||||
info is { Name.Length: > 0, Version.Length: > 0, ApiVersion: > 0, Capabilities: not null, Formats: not null, Limits: not null };
|
||||
|
||||
/// <summary>What a <c>server/info</c> answer is: Chronos's (with its info when it succeeded), something else, or unknown (busy).</summary>
|
||||
private readonly record struct Identity(bool? Chronos, ServerInfo? Info = null, bool Answered = true);
|
||||
/// <summary>
|
||||
/// What a <c>server/info</c> answer is: Chronos's (with its info when it succeeded, or its error when it failed),
|
||||
/// something else, or unknown (busy).
|
||||
/// </summary>
|
||||
private readonly record struct Identity(bool? Chronos, ServerInfo? Info = null, bool Answered = true, ApiError? Error = null);
|
||||
|
||||
/// <summary>
|
||||
/// Tells a <c>server/info</c> answer of Chronos from any other. Chronos answers it anonymously with its JSON and never
|
||||
@@ -138,7 +142,7 @@ public sealed class ChronosClient : IDisposable
|
||||
}
|
||||
if (!response.Headers.Contains(ApiVersion.Header)) return new(false);
|
||||
var error = await response.Content.ReadFromJsonAsync(ProtocolJson.Default.ApiError, ct).ConfigureAwait(false);
|
||||
return new(error is { Code.Length: > 0 } && !error.Code.StartsWith("http_", StringComparison.Ordinal));
|
||||
return error is { Code.Length: > 0 } && !error.Code.StartsWith("http_", StringComparison.Ordinal) ? new(true, Error: error) : new(false);
|
||||
}
|
||||
catch (Exception ex) when (ex is JsonException or NotSupportedException or HttpRequestException)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user