Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions modules/media/jsx/uploadForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,16 +345,18 @@ class MediaUploadForm extends Component {
} else {
let msg = this.props.t('Upload error!', {ns: 'media'});

if (xhr.response) {
if (xhr.statusText) {
msg = JSON.parse(xhr.response).message;
}
}
if (xhr.status === 409) {
msg = this.props.t('A file with the same name already exists!',
{ns: 'media'});
} else if (xhr.status === 413) {
msg = this.props.t('File too large!', {ns: 'media'});
} else if (xhr.response) {
try {
msg = JSON.parse(xhr.response).message;
} catch (e) {
// Ignore non-JSON responses.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we console.warn the error if it's not?

@priyavrat7 priyavrat7 Jun 30, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @driusan, the msg was already initialized at line 346, so ideally we do not need to do anything inside catch block. But if you suggest we can do something like this console.warn('Upload response was not valid JSON.'); for developers

@driusan driusan Jun 30, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant something like:

console.warn('Failed upload response was not valid JSON', e);

so that the error isn't lost silently in case it was significant. The try / catch is catching all errors.

console.warn('Upload response was not valid JSON', e);
}
}

this.setState({
Expand Down
Loading