fix(import): say what a proxy's reply means instead of its English reason phrase

A reply that is not the server's JSON (a reverse proxy's 502 page while the
container restarts, its 413 for a large body, a bare 500) reached the Import
screen as the HTTP reason phrase, in English, beside every photo. ErrorText now
uses an ApiError's message only when the server wrote it (a code that is not
TitanoClient's http_<status> fallback) and otherwise says what the status means:
too large, rate limited, not answering (gateway and timeout statuses) or a
server error. A card file that cannot be read while planning is listed with the
executor's catalog sentence instead of the system's text and full path.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
Claude committed 2026-10-12 16:21:10 +00:00
1 parent 789c2dae3e
commit 6e213d4997
6 files changed
+97 -6

No files matched your search

+23 -3
View File
@@ -1,4 +1,5 @@
using System.IO;
using System.Net;
using System.Net.Http;
using System.Reflection;
using Titano.Core.Archiving;
@@ -7,6 +8,7 @@ using Titano.Core.Localization;
using Titano.Core.Render;
using Titano.Data.Archiving;
using Titano.Data.Sync;
using Titano.Protocol;
using Titano.Protocol.Client;
namespace Titano.App.Shell;
@@ -21,8 +23,9 @@ public static class ErrorText
public static string For(Exception ex) => Describe(Unwrap(ex)) ?? Loc.L("Errors.Unexpected");
/// <summary>
/// A request to the signed-in server failed: the server's own sentence when it answered, else that it does not answer
/// (refused, timed out, dropped) or that its certificate is no longer trusted.
/// A request to the signed-in server failed: the server's own sentence when it answered, else what the reply's status
/// means (a proxy in front of it), that it does not answer (refused, timed out, dropped) or that its certificate is no
/// longer trusted.
/// </summary>
public static string ForServer(Exception ex)
{
@@ -40,11 +43,28 @@ public static class ErrorText
LeaseUnavailableException or ArchiveOfflineException or NewerFormatException or ImportSourceUnavailableException
or CopyVerificationException or StaleRenamePlanException or SyncConflictChangedException => ex.Message,
// The server words its errors in the client's language (Accept-Language).
TitanoApiException api when !string.IsNullOrWhiteSpace(api.Error.Message) => api.Error.Message,
TitanoApiException api when FromServer(api.Error) => api.Error.Message,
// Any other reply (a reverse proxy's 502 page while the server restarts, its 413 for a large body, a bare 500) holds
// only the HTTP reason phrase, in English: say what its status means.
TitanoApiException api => api.Status switch
{
HttpStatusCode.RequestEntityTooLarge => Loc.L("Server.Error.TooLarge"),
HttpStatusCode.TooManyRequests => Loc.L("Server.Error.RateLimited"),
_ when api.IsTransient => Loc.L("Server.Error.Unreachable"),
>= HttpStatusCode.InternalServerError => Loc.L("Server.Error.Internal"),
_ => null,
},
RenderException render => Loc.Get(render.ReasonKey, Loc.Culture) is null ? null : Loc.L(render.ReasonKey, [.. render.Args]),
_ => null,
};
/// <summary>
/// An error the server wrote as its JSON, with its own sentence. <c>TitanoClient</c> codes any other reply
/// <c>http_&lt;status&gt;</c> with the reason phrase as its message, and JSON of another shape has no code.
/// </summary>
private static bool FromServer(ApiError error) =>
error.Code is { } code && !code.StartsWith("http_", StringComparison.Ordinal) && !string.IsNullOrWhiteSpace(error.Message);
/// <summary>Awaited tasks and reflection wrap the real failure in one layer or more.</summary>
private static Exception Unwrap(Exception ex)
{
+5 -2
View File
@@ -62,7 +62,10 @@ public static class CardScanner
return files;
}
/// <summary>Reads light metadata of every file; unreadable files become <paramref name="problems"/>.</summary>
/// <summary>
/// Reads light metadata of every file; unreadable files become <paramref name="problems"/>, each with one localized
/// sentence (the system's text goes to the log only).
/// </summary>
public static IReadOnlyList<CardPhoto> ReadMetadata(string root, IReadOnlyList<CardFile> files, List<ImportProblem> problems,
IProgress<int>? progress = null, CancellationToken cancellationToken = default)
{
@@ -78,7 +81,7 @@ public static class CardScanner
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException)
{
Log.Warning("import", $"Cannot read {file.RelativePath}", ex);
problems.Add(new ImportProblem(file.RelativePath, ex.Message));
problems.Add(new ImportProblem(file.RelativePath, ImportExecutor.FailureText(ex)));
}
progress?.Report(i + 1);
}