havvg/http-exception
havvg/http-exception provides lightweight, framework-agnostic HTTP exception classes for PHP, covering common 4xx and 5xx status codes with reason phrases. Throw typed exceptions to signal HTTP errors and map them cleanly to responses or middleware.
getStatusCode(), reproducible in-house in under a day.symfony/http-kernel; legacy or non-Laravel PHP services that want named exception types without a framework; teams with a convention that prefers explicit classes over abort() or throwing generic HttpException.Consider it only in a narrow band:
symfony/http-kernel, Symfony, or Laravel.Look elsewhere — or build internally — when:
abort(404), Symfony\Component\HttpKernel\Exception\HttpException, NotFoundHttpException, and ValidationException already ship with the framework and are wired into the exception handler, logging, and render() pipeline. Adding a parallel hierarchy creates two error paths and confusion about which one Handler::render() sees.report()/render() contract expects Throwable; a foreign hierarchy works but gives you nothing extra.enum HttpStatus: int) — a modern PHP 8.1+ approach is shorter and more expressive.Practical guidance if you do adopt: pin an exact version, composer audit it, read all source first (it is small enough to read fully), and be prepared to vendor/fork it. Assume it is unmaintained.
For executives (one paragraph): A small open-source library exists that turns HTTP status codes into named exception classes. It is well-intentioned but has essentially no adoption — two GitHub stars, no downstream dependents, and a health score well below our threshold for third-party code. My recommendation is not to adopt it as a dependency. The capability it provides is roughly one file of our own code and is already partially provided by Laravel. This is a low-stakes, zero-cost decision: we take no risk, add no supply-chain surface, and still get the benefit. The real decision is broader — whether we standardize our API error responses — and that is where the effort should go.
For engineering: The pattern is worth adopting; the package is not. Typed exceptions (NotFoundException, ConflictException) make error handling self-documenting and let a single mapper translate domain failures into status codes. But in a Laravel codebase, Symfony\Component\HttpKernel\Exception\HttpException plus abort() already does this and is wired into Handler::render() and report(). Dropping in a second hierarchy gives us two error paths and no owners. Recommendation: spend half a day writing an internal App\Exceptions\Http\* set — or, better on PHP 8.1+, a HttpStatus enum and one HttpException with a status property — register it in bootstrap/app.php / the exception handler, and standardize the response envelope (status, code, message, details) in one place. That gets us the readability win, keeps one error path, and becomes ours to evolve.
Framing for the room: "Same outcome, less risk, similar effort. The package is a good idea with no community behind it — so we'll take the idea and leave the dependency."
How can I help you explore Laravel packages today?