Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve display of error returned from the REST API when an unsupported image type is uploaded #68788

Merged
Merged
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 @@ -134,9 +134,16 @@ export function uploadMedia( {
// Reset to empty on failure.
setAndUpdateFiles( index, null );

let message;
if ( error instanceof Error ) {
message = error.message;
let message: string;
adamsilverstein marked this conversation as resolved.
Show resolved Hide resolved
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
Loading