Skip to content

Surface real server error message on attachment upload failure - #3122

Open
wakqasahmed wants to merge 2 commits into
orchidsoftware:masterfrom
wakqasahmed:fix/attach-controller-403-error-message
Open

Surface real server error message on attachment upload failure#3122
wakqasahmed wants to merge 2 commits into
orchidsoftware:masterfrom
wakqasahmed:fix/attach-controller-403-error-message

Conversation

@wakqasahmed

Copy link
Copy Markdown
Contributor

Fixes #2927

Problem

When an attachment upload fails (e.g. the user lacks the system.attachment permission and the server responds 403 Forbidden), both attach_controller.js and cropper_controller.js ignore the actual server response and always show a hardcoded generic message:

  • attach_controller.js: always shows "The attached file must be an image", regardless of the real cause.
  • cropper_controller.js: always shows "File upload error".

This mislabels permission/authorization failures as file-type errors, giving users no useful information.

Fix

Both catch handlers now surface error.response?.data?.message (the message Laravel's exception handler returns in the JSON error body, e.g. "Forbidden" for an unhandled abort(403)) when present, falling back to the existing generic message otherwise. This mirrors the response shape already produced by AttachmentController's permission check (checkPermission() -> abort(403)).

Test plan

  • Verified via src/Platform/Http/Controllers/Controller.php's checkPermission() that a permission failure results in abort(403), and Laravel's default JSON exception response for this case is {"message": "Forbidden"}.
  • node --check on both modified files (no test runner/framework configured in this repo for JS controllers — no existing .test.js/.spec.js files or vitest/jest config to extend).
  • Manual verification in a running Orchid install (not available in this environment): remove system.attachment from a user, attempt an upload via an Attachment/Cropper field, confirm the toast now shows "Forbidden" instead of the file-type message.

wakqasahmed and others added 2 commits August 16, 2026 17:06
…rchidsoftware#2927)

Both attach_controller.js and cropper_controller.js swallowed the
actual server response and always showed a hardcoded 'file must be
an image' / 'File upload error' toast on any upload failure, so a
403 permission error (system.attachment) was mislabeled as a file
type error with no useful information for the user.

Surface error.response?.data?.message when the server provides one,
falling back to the existing generic message otherwise.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

No error message for 403 attachment exception

1 participant