Failing in a shape callers can readintermediate
A raw exception string tells the caller nothing they can act on; RFC 7807 ProblemDetails gives every failure the same machine-readable shape.
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.
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.
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.
A raw exception string tells the caller nothing they can act on; RFC 7807 ProblemDetails gives every failure the same machine-readable shape.
A discriminated union makes impossible states impossible: one status field the compiler forces you to handle, instead of three booleans that can contradict each other.