Skip to content

Commit

Permalink
Improve display of error returned from the REST API when an unsupport…
Browse files Browse the repository at this point in the history
…ed image type is uploaded (#68788)


Co-authored-by: adamsilverstein <[email protected]>
Co-authored-by: Mamaduka <[email protected]>
  • Loading branch information
3 people authored Feb 17, 2025
1 parent ffe84c3 commit eeb0d1b
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions packages/media-utils/src/utils/upload-media.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,16 @@ export function uploadMedia( {
// Reset to empty on failure.
setAndUpdateFiles( index, null );

let message;
if ( error instanceof Error ) {
message = error.message;
let message: string;
if (
typeof error === 'object' &&
error !== null &&
'message' in error
) {
message =
typeof error.message === 'string'
? error.message
: String( error.message );
} else {
message = sprintf(
// translators: %s: file name
Expand Down

0 comments on commit eeb0d1b

Please sign in to comment.