fix(upload): plain-language upload failure text instead of the raw MatrixError (#213)
The upload card printed the SDK's toString — 'MatrixError: [413] nope (http://<hs>/_matrix/media/v3/upload?filename=…)'. describeUploadError() maps the common cases to one sentence: 413/M_TOO_LARGE → 'This file is larger than the server allows (limit N)' using m.upload.size when known, 429 → 'Slow down — try again in a moment.', 401/403 → 'The server refused this upload: <server text>', 5xx/transport after the retry loop → 'Couldn't reach the server. Check your connection and retry.', other 4xx → the server's own sentence, URL stripped. Both card renderers use it; the raw error is still console.warn-ed by uploadContent for debugging. Unit-tested; verified headless with routed 413/403/503 responses. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PPmy3tPq869XDW4njjVaKA
This commit is contained in:
@@ -6,6 +6,7 @@ import { useMatrixClient } from '../../hooks/useMatrixClient';
|
||||
import { TUploadContent } from '../../utils/matrix';
|
||||
import { bytesToSize, getFileTypeIcon } from '../../utils/common';
|
||||
import { useMediaConfig } from '../../hooks/useMediaConfig';
|
||||
import { describeUploadError } from '../../utils/uploadError';
|
||||
|
||||
type CompactUploadCardRendererProps = {
|
||||
isEncrypted?: boolean;
|
||||
@@ -91,7 +92,7 @@ export function CompactUploadCardRenderer({
|
||||
)}
|
||||
{upload.status === UploadStatus.Error && (
|
||||
<UploadCardError>
|
||||
<Text size="T200">{upload.error.message}</Text>
|
||||
<Text size="T200">{describeUploadError(upload.error, allowSize)}</Text>
|
||||
</UploadCardError>
|
||||
)}
|
||||
{upload.status === UploadStatus.Idle && fileSizeExceeded && (
|
||||
|
||||
@@ -24,6 +24,7 @@ import {
|
||||
} from '../../state/room/roomInputDrafts';
|
||||
import { useObjectURL } from '../../hooks/useObjectURL';
|
||||
import { useMediaConfig } from '../../hooks/useMediaConfig';
|
||||
import { describeUploadError } from '../../utils/uploadError';
|
||||
import { compressImage, formatFileSize, isCompressible } from '../../utils/imageCompression';
|
||||
|
||||
type PreviewImageProps = {
|
||||
@@ -389,7 +390,7 @@ export function UploadCardRenderer({
|
||||
)}
|
||||
{upload.status === UploadStatus.Error && (
|
||||
<UploadCardError>
|
||||
<Text size="T200">{upload.error.message}</Text>
|
||||
<Text size="T200">{describeUploadError(upload.error, allowSize)}</Text>
|
||||
</UploadCardError>
|
||||
)}
|
||||
{upload.status === UploadStatus.Idle && fileSizeExceeded && (
|
||||
|
||||
Reference in New Issue
Block a user