Skip to content

Improve error handling and fix format issues - #5593

Open
murshed wants to merge 1 commit into
WordPress:mainfrom
murshed:main
Open

Improve error handling and fix format issues#5593
murshed wants to merge 1 commit into
WordPress:mainfrom
murshed:main

Conversation

@murshed

@murshed murshed commented Jul 27, 2026

Copy link
Copy Markdown

Fix DRF serializer error format, oEmbed exception handling, shell JSON escaping, and skip button focus CSS

Description

This pull request addresses several reliability, compatibility, and accessibility issues across the repository:

  • Fix serializer error format to be DRF-compliant in OembedRequestSerializer:
    Updated the ValidationError error dictionary structure from {"Could not parse identifier from URL.": data["url"]} to standard DRF-compliant structure {"url": ["Could not parse identifier from URL."]} in api/api/serializers/image_serializers.py. This aligns with the OpenAPI specification (image_oembed_400_example) and standard PHP / WordPress client expectations.

  • Add error handling and logging for image dimension fetching in oEmbed endpoint:
    Wrapped out-of-band image downloading and PIL image dimension parsing in a try...except block in api/api/views/image_views.py. Structured warnings (failed_to_get_image_dimensions_for_oembed) are logged when network or parsing errors occur, preventing unhandled HTTP 500 responses.

  • Add HTTP status check before processing image content:
    Added explicit image_file.status == 200 verification before reading image content bytes and attempting PIL dimension extraction in image_views.py.

  • Escape special characters in dag-sync.sh JSON payload for robustness:
    Added parameter expansion rules ${subject//\\/\\\\} and ${subject//\"/\\\"} in dag-sync.sh to escape backslashes and double quotes in commit messages before constructing Slack webhook JSON payloads.

  • Update skip button CSS selector for better browser compatibility:
    Updated the CSS selector in frontend/src/components/VSkipToContentButton.vue to .skip-button:not(:focus, :focus-visible) so the skip-to-content button is visually displayed whenever focused across all browser focus modes.

Testing Instructions

  1. API / oEmbed Serializer & View:
    • Query v1/images/oembed/ with an invalid url parameter (e.g., ?url=invalid) and verify that the 400 response body is formatted as {"url": ["Could not parse identifier from URL."]}.
    • Query v1/images/oembed/ for an image whose remote URL returns 404 or times out, and verify that the view returns a valid 200 oEmbed response without throwing a 500 Internal Server Error.
  2. Shell Script:
    • Run bash -n dag-sync.sh to verify syntax correctness.
  3. Frontend:
    • Tab into the frontend application and verify that the "Skip to content" button displays properly upon receiving focus.

Checklist

  • My pull request has a descriptive title (not a vague title like Update index.md).
  • My pull request targets the default branch of the repository (main) or a parent feature branch.
  • My commit messages follow best practices.
  • My code follows the established code style of the repository.
  • I added or updated tests for the changes I made (if applicable).
  • I added or updated documentation (if applicable).
  • I tried running the project locally and verified that there are no visible errors.
  • I ran the DAG documentation generator (ov just catalog/generate-docs for catalog PRs) or the media properties generator (ov just catalog/generate-docs media-props for the catalog or ov just api/generate-docs for the API) where applicable.

Developer Certificate of Origin

Developer Certificate of Origin
Developer Certificate of Origin
Version 1.1

Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
1 Letterman Drive
Suite D4700
San Francisco, CA, 94129

Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.


Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.

- Fix serializer error format to be DRF-compliant in OembedRequestSerializer
- Add error handling and logging for image dimension fetching in oEmbed endpoint
- Add HTTP status check before processing image content
- Escape special characters in dag-sync.sh JSON payload for robustness
- Update skip button CSS selector for better browser compatibility
@murshed
murshed requested review from a team as code owners July 27, 2026 08:58
@murshed
murshed requested review from dhruvkb and obulat July 27, 2026 08:58
@openverse-bot openverse-bot added 🧱 stack: api Related to the Django API 🧱 stack: frontend Related to the Nuxt frontend 🚦 status: awaiting triage Has not been triaged & therefore, not ready for work labels Jul 27, 2026
@openverse-bot openverse-bot moved this to 👀 Needs Review in Openverse PRs Jul 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🧱 stack: api Related to the Django API 🧱 stack: frontend Related to the Nuxt frontend 🚦 status: awaiting triage Has not been triaged & therefore, not ready for work

Projects

Status: 👀 Needs Review

Development

Successfully merging this pull request may close these issues.

2 participants