@@ -63,7 +63,12 @@ import { blobIsAnimated } from "./utils/Image.ts";
6363const PHYS_HIDPI = [ 0x00 , 0x00 , 0x16 , 0x25 , 0x00 , 0x00 , 0x16 , 0x25 , 0x01 ] ;
6464
6565export 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+ }
6772
6873interface IMediaConfig {
6974 "m.upload.size" ?: number ;
@@ -367,7 +372,7 @@ export async function uploadFile(
367372 } catch ( e ) {
368373 if ( abortController . signal . aborted ) throw new UploadCanceledError ( ) ;
369374 console . error ( "Failed to upload file" , e ) ;
370- throw new UploadFailedError ( ) ;
375+ throw new UploadFailedError ( e ) ;
371376 }
372377 if ( abortController . signal . aborted ) throw new UploadCanceledError ( ) ;
373378
@@ -386,7 +391,7 @@ export async function uploadFile(
386391 } catch ( e ) {
387392 if ( abortController . signal . aborted ) throw new UploadCanceledError ( ) ;
388393 console . error ( "Failed to upload file" , e ) ;
389- throw new UploadFailedError ( ) ;
394+ throw new UploadFailedError ( e ) ;
390395 }
391396 if ( abortController . signal . aborted ) throw new UploadCanceledError ( ) ;
392397 // If the attachment isn't encrypted then include the URL directly.
@@ -638,15 +643,18 @@ export default class ContentMessages {
638643 dis . dispatch < UploadFinishedPayload > ( { action : Action . UploadFinished , upload } ) ;
639644 dis . dispatch ( { action : "message_sent" } ) ;
640645 } catch ( error ) {
646+ // Unwrap UploadFailedError to get the underlying error
647+ const unwrappedError = error instanceof UploadFailedError && error . cause ? error . cause : error ;
648+
641649 // 413: File was too big or upset the server in some way:
642650 // 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 ) {
644652 this . mediaConfig = null ;
645653 }
646654
647655 if ( ! upload . cancelled ) {
648656 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 ) {
650658 desc = _t ( "upload_failed_size" , {
651659 fileName : upload . fileName ,
652660 } ) ;
0 commit comments