PHPackages                             kamranahmedse/laravel-faulty - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. kamranahmedse/laravel-faulty

ActiveLibrary

kamranahmedse/laravel-faulty
============================

A minimal package to assist in returning RESTful exceptions in your APIs.

1.1.1(9y ago)6318.4k↓33.3%7MITPHP

Since Aug 5Pushed 9y ago3 watchersCompare

[ Source](https://github.com/kamranahmedse/laravel-faulty)[ Packagist](https://packagist.org/packages/kamranahmedse/laravel-faulty)[ RSS](/packages/kamranahmedse-laravel-faulty/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)Dependencies (1)Versions (5)Used By (0)

Laravel Faulty - RESTful Exceptions
===================================

[](#laravel-faulty---restful-exceptions)

> Automatically turns your thrown exceptions (HTTP/non-HTTP) to the JSON response while conforming to API problem specification.

A Laravel/Lumen package that lets you handle the API problems with ease.

Faulty provides a straightforward implementation of [IETF Problem Specification](https://tools.ietf.org/html/draft-nottingham-http-problem-07) and turns your exceptions to be returned in the below format with the content type of `application/problem+json`

```
{
   "status": 403,
   "type": "http://example.com/problems/out-of-credit",
   "title": "You do not have enough credit.",
   "detail": "Your current balance is 30, but that costs 50.",
   "instance": "http://example.net/account/12345/logs?id=233"
}
```

Where

- `type` is the absolute URI that identifies the type of problem
- `title` is the summary of problem
- `status` is the status code
- `detail` is human readable explanation specific to problem
- `instance` is the absolute URI that identifies the specific occurrence of the problem

Installation
------------

[](#installation)

Run the below command

```
composer require kamranahmedse/laravel-faulty

```

Make your exception handler i.e. `App\Exceptions\Handler` that can be found at `app\Exceptions\Handler.php` extend from the Faulty's handler i.e.

```
use KamranAhmed\Faulty\Handler as FaultyHandler;

class Handler extends FaultyHandler {
   // ...
}
```

And that's it. You are all set to use Faulty.

\##Configuration Faulty relies on the following environment configurations

- `APP_DEBUG` : If `true`, exceptions will be rendered with whoops, if false JSON will be returned. **Defaults to `false`**
- `APP_DEBUG_TRACE` : If true, stack trace will be included in the application errors. **Defaults to `true`**

Usage
-----

[](#usage)

For HTTP exceptions to be rendered properly with the proper status codes, you should use the exception classes provided by faulty i.e. the ones available in `Faulty\Exceptions` namespace or use the relevant ones provided by the Symfony's HTTP component i.e. the ones available under `Symfony\Component\HttpKernel\Exception`

\###Throwing Exceptions

All the exception classes have the below signature

```
use KamranAhmed\Faulty\Exceptions\[ProblemType]Exception;
[ProblemType]Exception($detail, $title = '', $instance = '', $type = '')
```

Here are some of the provided exception classes

```
// Include the exception classes from the given namespace

throw new BadRequestException('Invalid request data');
throw new ConflictException('Same request is already pending');
throw new ForbiddenException('You are not allowed to perform this action');
throw new InternalErrorException('Exports directory isn\'t writable');
throw new NoContentException('Deletion request successfuly accepted');
throw new NotFoundException('Item not found');
throw new NotModifiedException('..');
throw new PaymentRequiredException('..');
throw new PreconditionFailedException('..');
throw new ProcessingException('..');
throw new RequestTimeoutException('..');
throw new RequestTooLongException('..');
throw new UnauthorizedException('..');
throw new UnprocessableEntityException('..');
```

Also, if you would like to return any response for which the exception class isn't available, you can use the `HttpException` class i.e.

```
use KamranAhmed\Faulty\Exceptions\HttpException;

throw new HttpException($title = '', $status = 500, $detail = '', $instance = '', $type = '');
```

### Syntactic Sugar

[](#syntactic-sugar)

Also, for any of the exception classes above, you can use the below syntax as well.

```
$typeUrl = route('api.problem', ['type' => 'forbidden']);
$occurence = route('account.error', ['account_id' => 'A837332A', 'log_id' => 34]);

(new ForbiddenException("Your account doesn't have the balance of 50 USD"))
    ->setTitle('Balance too low)
    ->setType($problemRoute)
    ->setInstance($occurence)
    ->toss();
```

Also, if you would like to send additional data in response, call the method `setAdditional([])` on the error object while passing the additional detail i.e.

```
(new ForbiddenException("Your account doesn't have the balance of 50 USD"))
    ->setTitle('Balance too low)
    ->setAdditional([
        'current_balance' => 40,
        'required_balance' => 50,
        'item_detail' => $itemArray
    ])
    ->toss();
```

Contributing
------------

[](#contributing)

Feel free to fork, enhance, create PR and lock issues.

License
-------

[](#license)

MIT © [Kamran Ahmed](http://kamranahmed.info)

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity40

Moderate usage in the ecosystem

Community11

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~65 days

Total

4

Last Release

3376d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e119260b816ceaf3e92000b32fc38122e255b463ec0c23b37568f46da2ac0b77?d=identicon)[kamranahmedse](/maintainers/kamranahmedse)

---

Top Contributors

[![kamranahmedse](https://avatars.githubusercontent.com/u/4921183?v=4)](https://github.com/kamranahmedse "kamranahmedse (21 commits)")

---

Tags

laravellumenexceptionerrorwhoopserrorsexceptionsapi-problemlaravel faulty

### Embed Badge

![Health badge](/badges/kamranahmedse-laravel-faulty/health.svg)

```
[![Health](https://phpackages.com/badges/kamranahmedse-laravel-faulty/health.svg)](https://phpackages.com/packages/kamranahmedse-laravel-faulty)
```

###  Alternatives

[graham-campbell/exceptions

Provides A Powerful Error Response System For Both Development And Production

5911.3M4](/packages/graham-campbell-exceptions)[zeuxisoo/slim-whoops

PHP whoops error on slim framework

1371.1M27](/packages/zeuxisoo-slim-whoops)[facile-it/sentry-module

This module allows integration of Sentry Client into laminas and mezzio

19372.5k](/packages/facile-it-sentry-module)[guanguans/laravel-exception-notify

Monitor exception and report to the notification channels(Log、Mail、AnPush、Bark、Chanify、DingTalk、Discord、Gitter、GoogleChat、IGot、Lark、Mattermost、MicrosoftTeams、NowPush、Ntfy、Push、Pushback、PushBullet、PushDeer、PushMe、Pushover、PushPlus、QQ、RocketChat、ServerChan、ShowdocPush、SimplePush、Slack、Telegram、WeWork、WPush、XiZhi、YiFengChuanHua、ZohoCliq、ZohoCliqWebHook、Zulip).

14642.7k1](/packages/guanguans-laravel-exception-notify)[topshelfcraft/canary

The kinder, cuter, cleverer Craft error handler.

114.4k](/packages/topshelfcraft-canary)[thehocinesaad/laravel-error-ai

This package adds Ask AI button to the error page.

2214.4k](/packages/thehocinesaad-laravel-error-ai)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
