@@ -63,7 +63,12 @@ import { blobIsAnimated } from "./utils/Image.ts";
63
63
const PHYS_HIDPI = [ 0x00 , 0x00 , 0x16 , 0x25 , 0x00 , 0x00 , 0x16 , 0x25 , 0x01 ] ;
64
64
65
65
export class UploadCanceledError extends Error { }
66
- export class UploadFailedError extends Error { }
66
+ export class UploadFailedError extends Error {
67
+ public constructor ( cause : any ) {
68
+ super ( ) ;
69
+ this . cause = cause ;
70
+ }
71
+ }
67
72
68
73
interface IMediaConfig {
69
74
"m.upload.size" ?: number ;
@@ -367,7 +372,7 @@ export async function uploadFile(
367
372
} catch ( e ) {
368
373
if ( abortController . signal . aborted ) throw new UploadCanceledError ( ) ;
369
374
console . error ( "Failed to upload file" , e ) ;
370
- throw new UploadFailedError ( ) ;
375
+ throw new UploadFailedError ( e ) ;
371
376
}
372
377
if ( abortController . signal . aborted ) throw new UploadCanceledError ( ) ;
373
378
@@ -386,7 +391,7 @@ export async function uploadFile(
386
391
} catch ( e ) {
387
392
if ( abortController . signal . aborted ) throw new UploadCanceledError ( ) ;
388
393
console . error ( "Failed to upload file" , e ) ;
389
- throw new UploadFailedError ( ) ;
394
+ throw new UploadFailedError ( e ) ;
390
395
}
391
396
if ( abortController . signal . aborted ) throw new UploadCanceledError ( ) ;
392
397
// If the attachment isn't encrypted then include the URL directly.
@@ -638,15 +643,18 @@ export default class ContentMessages {
638
643
dis . dispatch < UploadFinishedPayload > ( { action : Action . UploadFinished , upload } ) ;
639
644
dis . dispatch ( { action : "message_sent" } ) ;
640
645
} catch ( error ) {
646
+ // Unwrap UploadFailedError to get the underlying error
647
+ const unwrappedError = error instanceof UploadFailedError && error . cause ? error . cause : error ;
648
+
641
649
// 413: File was too big or upset the server in some way:
642
650
// clear the media size limit so we fetch it again next time we try to upload
643
- if ( error instanceof HTTPError && error . httpStatus === 413 ) {
651
+ if ( unwrappedError instanceof HTTPError && unwrappedError . httpStatus === 413 ) {
644
652
this . mediaConfig = null ;
645
653
}
646
654
647
655
if ( ! upload . cancelled ) {
648
656
let desc = _t ( "upload_failed_generic" , { fileName : upload . fileName } ) ;
649
- if ( error instanceof HTTPError && error . httpStatus === 413 ) {
657
+ if ( unwrappedError instanceof HTTPError && unwrappedError . httpStatus === 413 ) {
650
658
desc = _t ( "upload_failed_size" , {
651
659
fileName : upload . fileName ,
652
660
} ) ;
0 commit comments