Skip to content

Handle file paths as not found in delivery API by route requests#19063

Merged
AndyButland merged 3 commits intov13/devfrom
v13/bugfix/handle-file-requests-with-404-in-delivery-api
Apr 22, 2025
Merged

Handle file paths as not found in delivery API by route requests#19063
AndyButland merged 3 commits intov13/devfrom
v13/bugfix/handle-file-requests-with-404-in-delivery-api

Conversation

@AndyButland
Copy link
Contributor

@AndyButland AndyButland commented Apr 16, 2025

Prerequisites

  • I have added steps to test this contribution in the description below

Resolves: #19051

Description

As the linked issue shows, a request to the delivery API to retrieve a content item by route will fail with a 500 rather than a 404 for a file path request. This is because there's no Umbraco context available for these requests and an exception is thrown as one is expected to exist.

In this update I've checked for a file request and where found, immediately return null and hence 404 to the caller.

Note that this doesn't happen on 15 - due to the removal of the "published snapshot" - a 404 is returned already on this version. So the fix is needed only for 15.

Testing

  • Make a delivery API request to an existing route, e.g. /umbraco/delivery/api/v2/content/item/my-folder/my-page, and verify the expected 200 response is returned.
  • Make a delivery API request to a non-existing route, e.g. /umbraco/delivery/api/v2/content/item/my-folder/my-missing-page, and verify the expected 404 response is returned.
  • Make a delivery API request to a file, e.g. /umbraco/delivery/api/v2/content/item/my-folder/my-file.txt, and verify that now a 404 response is returned.

Copilot AI review requested due to automatic review settings April 16, 2025 14:12
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

Copy link
Contributor

@kjac kjac left a comment

Choose a reason for hiding this comment

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

Works like a charm. Good stuff!

I renamed "resolveable" to "resolvable" - Google says that's the correct spelling 🤷

@AndyButland AndyButland merged commit c6effef into v13/dev Apr 22, 2025
15 of 19 checks passed
@AndyButland AndyButland deleted the v13/bugfix/handle-file-requests-with-404-in-delivery-api branch April 22, 2025 04:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants