thinknimble/tn-spa-bootstrapper

SPA app HTTP responses are always 200 (never 404)

Opened this issue · 0 comments

Vue (and other SPAs) will always return an HTTP 200 response, even on a page not found 404.
This is because HTTP responses happen at a lower level.

We could pass 404s to the server and let the server return a proper 404, but that would limit having a more advanced 404 page.

This was the issue with this PR: #212

There are some ideas out there on how to do this better:
https://stackoverflow.com/questions/54218371/how-to-get-a-404-response-in-vue-router
https://stackoverflow.com/questions/73098868/vuejs-real-seo-friendly-404-page-for-search-engines-like-google-msn

The original reason I tried to solve this was because of backend tests being written to test the API, checking that the response was 200 (which it always was) and not realizing that the test was failing because of a mis-typed URL.

One possible idea:
Create a pytest fixture, mock, and/or Cypress utility that intercepts calls, inspects the payload for an error, and then fails the test.

This is expected behavior so not technically a bug. But something that could be improved anyway.