forgejo/web_src/js
steven.guiheux 6574dba902 fix(ui): handle non-JSON error responses in form-fetch-action (#12635)
### Problem

When a user clicks the merge button on a pull request and their quota is exceeded, the UI displays ( cf screenshot ):

> Network error SyntaxError: Unexpected token 'Q', "Quota exceeded." is not valid JSON

### Fix

Read the response body as text first with `resp.text()`, then attempt `JSON.parse()`. If parsing succeeds, use the existing `errorMessage` logic. If it fails, display the raw text directly in the error toast.

This is the same approach already used by Dropzone for attachment uploads, where the `error` event handler passes the response body directly to `showErrorToast`. ( cf screenshot )

### Tests for JavaScript changes

The function is not exported, I cannot create a unit test. Do you want me to export all the logic in an exported function ?

### Release notes

- [X] This change will be noticed by a Forgejo user or admin (feature, bug fix, performance, etc.). I suggest to include a release note for this change.

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/12635
Reviewed-by: Mathieu Fenniak <mfenniak@noreply.codeberg.org>
2026-05-19 21:09:44 +02:00
..
components feat: mark skipped checks as skipped (#12606) 2026-05-17 18:00:49 +02:00
features fix(ui): handle non-JSON error responses in form-fetch-action (#12635) 2026-05-19 21:09:44 +02:00
markup fix: Fix invisible iframes with RENDER_CONTENT_MODE=iframe (#8378) 2025-09-06 16:23:01 +02:00
modules feat: migrate show-modal to native dialogs (#10287) 2026-05-03 06:42:14 +02:00
render fix: don't show ConEmu OSC escape sequences (#9875) 2025-10-31 07:24:23 +01:00
standalone chore(ui): change /devtest to /-/demo (#11019) 2026-01-26 13:12:25 +01:00
utils fix: prevent page jumps due to textarea auto resizing (#7569) 2025-10-01 03:47:19 +02:00
vendor Vendor jquery.are-you-sure with strict mode fixes (#26901) 2023-09-06 00:02:44 +00:00
webcomponents fix(ui): make relative time consistent with other text when selected (#11231) 2026-02-11 15:34:31 +01:00
bootstrap.js feat(ui): replace Monaco with CodeMirror (#10559) 2026-01-04 23:52:33 +01:00
bootstrap.test.js Avoid duplicate JS error messages on UI (#28873) 2024-01-21 14:23:08 +00:00
emoji.test.js chore: add javascript unit test 2025-08-10 23:11:39 +02:00
globals.d.ts feat(ui): replace Monaco with CodeMirror (#10559) 2026-01-04 23:52:33 +01:00
htmx.js feat: add admin moderation actions for abuse reports and for reported abusive content (#8716) 2025-12-03 20:07:32 +01:00
index.js feat: view authorized integration (generic) 2026-05-14 23:54:16 +02:00
jquery.js Forbid variables containing jQuery collections not having the $ prefix (#29839) 2024-03-20 08:46:30 +01:00
svg.js feat(ui): replace Monaco with CodeMirror (#10559) 2026-01-04 23:52:33 +01:00
svg.test.js Remove "class-name" from svg icon (#33540) 2025-02-25 12:56:30 +01:00
types.d.ts feat: migrate show-modal to native dialogs (#10287) 2026-05-03 06:42:14 +02:00
utils.js chore: add new lint rules 2024-10-23 08:10:18 +02:00
utils.test.js chore(ci): testSleep: show actual times on failures (#8271) 2025-06-25 15:58:55 +02:00
vitest.setup.js feat: replace cross origin protection (#9830) 2025-10-29 22:43:22 +01:00