Heimdall start refusal: log the HTTP status and Heimdall's error code
The journal said only 'Heimdall rejected the auth start', which cannot tell a wrong app secret (401 app_auth_required) from a fault. The message now carries the status and, when the body has one, an error code that is a short snake_case token; no other body text is echoed. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
fe0ff40864
commit
c085cead9d
2 changed files with 50 additions and 2 deletions
|
|
@ -53,6 +53,32 @@ public sealed class HeimdallAuthService(
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Names the HTTP status and, when the body carries one, Heimdall's error code. The code is shown only
|
||||
/// if it is a short snake_case token, so nothing else from the body (free text, tokens) reaches a log.
|
||||
/// </summary>
|
||||
private static async Task<string> RefusedStartMessageAsync(HttpResponseMessage response, CancellationToken cancellationToken)
|
||||
{
|
||||
var detail = $"HTTP {(int)response.StatusCode}";
|
||||
try
|
||||
{
|
||||
var body = await response.Content.ReadFromJsonAsync<JsonElement>(cancellationToken);
|
||||
if (body.ValueKind == JsonValueKind.Object
|
||||
&& body.TryGetProperty("error", out var error)
|
||||
&& error.ValueKind == JsonValueKind.String
|
||||
&& error.GetString() is { Length: > 0 and <= 64 } code
|
||||
&& code.All(c => c is (>= 'a' and <= 'z') or (>= '0' and <= '9') or '_'))
|
||||
{
|
||||
detail += ", " + code;
|
||||
}
|
||||
}
|
||||
catch (JsonException)
|
||||
{
|
||||
}
|
||||
|
||||
return $"Heimdall rejected the auth start ({detail}).";
|
||||
}
|
||||
|
||||
public async Task<HeimdallAuthStartResult> StartAsync(
|
||||
string provider,
|
||||
string callbackBaseUrl,
|
||||
|
|
@ -91,7 +117,7 @@ public sealed class HeimdallAuthService(
|
|||
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
throw new HeimdallAuthException("Heimdall rejected the auth start.");
|
||||
throw new HeimdallAuthException(await RefusedStartMessageAsync(response, cancellationToken));
|
||||
}
|
||||
|
||||
var payload = await response.Content.ReadFromJsonAsync<HeimdallStartResponse>(cancellationToken);
|
||||
|
|
|
|||
Loading…
Reference in a new issue