So far, everything in the Kladde works fine as long as nobody does anything unexpected. Whoever opens /contacts/99 gets a sentence with
status code 200, whoever mistypes the address gets a bare 404 without a page, and if an exception is thrown on a page, you see an empty page
or JSON in the browser, depending on the environment. In this lesson, each of these cases gets an answer that’s understandable for people
and correct for machines.
Missing, empty or broken
Three cases look similar at first glance and aren’t:
| Case | Example | Status code | what the page shows |
|---|---|---|---|
| missing | /contacts/99 if the contact doesn’t exist; /contcats with a typo |
404 | a “not found” page with ways back |
| empty | the search for zzz; a day without free times |
200 | the normal page with a sentence instead of the list |
| broken | the database doesn’t answer; an error in the code | 500 | an error page without details; they’re in the log |
An empty list isn’t an error. The search worked, it just found nothing, and the page says so in one sentence. You built it that way in
lessons 2.5.4 and 2.5.6 already. A 404 would be wrong there, because the page /contacts?q=zzz does exist.
The status code isn’t just politeness toward machines. Search engines add a page with 200 to their index even if it says “not found” on it. Monitoring counts 500s, and an error that answers with 200 goes unnoticed. And a test in module 2.7 checks status codes, not sentences.