I want to show users of my webapp a "Resource not found" message when the requested path is not found (404) on the backend API.
To do that, the CORS preflight have to succeed (200 OK), so that the real request can give the 404 response.
Client use-case example:
fetch('https://api.example.com/path/not/found/on/server')
.then(response => {
const payload = await response.json()
if (response.ok) {
return { status: 'success', payload: payload }
} else {
// Never gets here!
return { status: 'error', message: payload.message, httpStatus: response.status }
}
})
.catch(e => {
// Gets here with a not very helpful error message, and lost response.status
// Chrome: "Failed to fetch"
// Firefox: "NetworkError when attempting to fetch resource."
return { status: 'error', message: e.toString() }
})
CORS preflight succeeding for unknown path would give:
I want to show users of my webapp a "Resource not found" message when the requested path is not found (404) on the backend API.
To do that, the CORS preflight have to succeed (200 OK), so that the real request can give the 404 response.
Client use-case example:
CORS preflight succeeding for unknown path would give: