WeCodeAcademy

Step 3: Status codes and the error rate

Status codes group by their first digit: 2xx success, 3xx redirect, 4xx the client made a mistake (not found, not allowed), 5xx the server failed. A 5xx is your problem, so it matters most. A Counter groups codes in one line, and the error rate is errors divided by total requests.

Examplepython
Open in editor »

The 500s on /api/progress stand out. A healthy site keeps 5xx close to zero, and rising 5xx is what wakes people up at night.

Your turn: write the code

Write error_rate(statuses) that returns the fraction of status codes that are 400 or higher, rounded to 2 decimals (0 for an empty list). Print error_rate([200, 200, 404, 500]) and error_rate([]).

Quick check

Which status class means the server itself failed?

Finish the quick check (and any code exercise) to complete this lesson, or mark it done yourself.

Tip: use the left and right arrow keys to move between lessons.