A Typed Exception Hierarchy That Maps to HTTP
The MongrelDB PHP client maps HTTP status codes to a small typed exception hierarchy, so a 401 is an AuthException, a 409 is a ConstraintException carrying the server's error code and the failing operation index, and your catch blocks read like the failure modes they handle.