HomeChallengesRepsProblemsLeaderboardTake a challenge

The order that isn’t there

GET /orders/2 finds nothing, because the id from the URL is a string; GET /orders/99 answers 200 with an empty body; and an unknown route gets a text page. Make a miss say so, in JSON, with a status a client can act on.

Beginner8 min on the clock5 graded checks · 100 pointsTyped Express
Graded by running your code against real cases.

What you build

  • Type params as Request<{ id: string }> and convert the id to a number
  • Return 400 when the id is not a number
  • Return 404 with an ErrorBody when there is no such order
  • Add a JSON catch-all 404 after the routes
  • Type the response as Response<Order | ErrorBody>

Done means

A hit is 200, a miss 404 with an error body, a bad id 400, an unknown route a JSON 404, and both outcomes are in the type.

How it is graded

Published in full, before you start — every point is one of these and there is nothing else. Each one runs your code; it is not a search for keywords.

  1. /orders/2 returns order 2+20Failing in a shape callers can read
  2. /orders/99 is a 404 with an error body+25Failing in a shape callers can read
  3. /orders/abc is a 400+20Failing in a shape callers can read
  4. An unknown route gets a JSON 404+15Failing in a shape callers can read
  5. The response is Response<Order | ErrorBody>+20Union types and narrowing

What it teaches

The rest of Typed Express