Worker Fetch, status 500, 501, 503 and 505

Currently working on a piece of functionality where we are looking to implement a Cloudflare worker to handle status codes and then redirect them when they are identified. Custom pages at present does not handle 500, 501, 503, and 505 errors, therefore we would need Cloudflare worker to identify these, if found to redirect end user to http://exmaple.com (as an example).

Is there any example of this sort of functionality?

There’s no straightforward tutorial for this, but you can refer to these few examples and try to make your own condition:

https://developers.cloudflare.com/workers/examples/redirect

https://developers.cloudflare.com/workers/runtime-apis/response

Something like:

if response.status equals to 500 or 501 or 503 or 505, then Response.redirect("https://www.example.com", 301)

We are looking to use the Fetch feature rather than redirect to avoid the URL from changing for the end user.

Then this is something you are looking for:

https://developers.cloudflare.com/workers/examples/respond-with-another-site

if response.status equals to 500 or 501 or 503 or 505, then return fetch("https://another.site")

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.