Skip to content

[modules | media] Fix media upload error handling for non-JSON server responses#10700

Merged
driusan merged 2 commits into
aces:29.0-releasefrom
priyavrat7:2026_06_28_Form_freezes_when_uploading_file_size_bigger_than_2G
Jun 30, 2026
Merged

[modules | media] Fix media upload error handling for non-JSON server responses#10700
driusan merged 2 commits into
aces:29.0-releasefrom
priyavrat7:2026_06_28_Form_freezes_when_uploading_file_size_bigger_than_2G

Conversation

@priyavrat7

@priyavrat7 priyavrat7 commented Jun 29, 2026

Copy link
Copy Markdown

closes #10659

Situation

Uploading a file larger than the configured limit in the LORIS Media module caused the browser to freeze and show JavaScript stack traces. The initial assumption was that the backend was failing, but the actual failure mode was in the frontend response handling.

Task

Identify the root cause of the upload failure, verify it against the nginx-based VM behavior, and update the upload flow so it can safely handle non-JSON error responses.

Action

I reproduced the issue on the test VM, confirmed that oversized uploads were rejected by nginx with an HTML 413 response as shown in the screenshot, and traced the crash to unconditional JSON.parse() calls in the upload handler. I updated the logic to parse responses defensively with `try/catch.
image

Result

The frontend should not freeze or crash when the server returns HTML instead of JSON. Oversized uploads now fall back to the default error message.

Testing Instructions for a VM with nginx

  1. Confirm the VM is using nginx and has the expected upload limit configured.
  2. Open the Media upload page.
  3. Upload a file larger than the configured limit.
  4. Upload the file using the expected filename convention so the frontend accepts it.
  5. Verify that nginx returns 413 Request Entity Too Large and that the response body is HTML.
  6. Confirm the browser does not throw Unexpected token '<' in the console.
  7. Confirm the upload flow shows the default error message instead of freezing.

The media upload flow assumed every error response was JSON and attempted to parse
the response unconditionally. When nginx rejected oversized uploads with an HTML
413 response, the browser threw an Unexpected token '<' exception and the upload
error handling failed.

This change wraps JSON parsing in defensive try/catch handling so HTML or other
non-JSON responses fall back to the default error message instead of crashing the
frontend.
@priyavrat7 priyavrat7 added Category: Bug PR or issue that aims to report or fix a bug Area: UI PR or issue related to the user interface Language: Javascript PR or issue that update Javascript code Module: media PR or issue related to media module 29.0.0 - Bugs Issues found during the release testing for 29.0.0 labels Jun 29, 2026
@CamilleBeau CamilleBeau requested a review from skarya22 June 29, 2026 18:27

@skarya22 skarya22 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM! I tried to upload a 3G file on Chrome on 29.0-release and it froze, but when I switched to this branch and re-compiled I got a File Too Large error. The problem was not present on Firefox.

@skarya22 skarya22 added the Passed manual tests PR has been successfully tested by at least one peer label Jun 30, 2026
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.

@driusan driusan merged commit 1434fd2 into aces:29.0-release Jun 30, 2026
21 checks passed
kongtiaowang pushed a commit to kongtiaowang/Loris that referenced this pull request Jul 2, 2026
… responses (aces#10700)

Uploading a file larger than the configured limit in the LORIS Media
module caused the browser to freeze and show JavaScript stack traces.
The initial assumption was that the backend was failing, but the actual
failure mode was in the frontend response handling.

The frontend should not freeze or crash when the server returns HTML
instead of JSON. Oversized uploads now fall back to the default error
message.

Fixes aces#10659
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

29.0.0 - Bugs Issues found during the release testing for 29.0.0 Area: UI PR or issue related to the user interface Category: Bug PR or issue that aims to report or fix a bug Language: Javascript PR or issue that update Javascript code Module: media PR or issue related to media module Passed manual tests PR has been successfully tested by at least one peer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[media] Uploading a big file should produce an error but nothing happens..

3 participants