Download the PHP package kamranahmedse/laravel-faulty without Composer
On this page you can find all versions of the php package kamranahmedse/laravel-faulty. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download kamranahmedse/laravel-faulty
More information about kamranahmedse/laravel-faulty
Files in kamranahmedse/laravel-faulty
Package laravel-faulty
Short Description A minimal package to assist in returning RESTful exceptions in your APIs.
License MIT
Informations about the package laravel-faulty
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 and turns your exceptions to be returned in the below format with the content type of application/problem+json
Where
type
is the absolute URI that identifies the type of problemtitle
is the summary of problemstatus
is the status codedetail
is human readable explanation specific to probleminstance
is the absolute URI that identifies the specific occurrence of the problem
Installation
Run the below command
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.
And that's it. You are all set to use Faulty.
Configuration
Faulty relies on the following environment configurations
APP_DEBUG
: Iftrue
, exceptions will be rendered with whoops, if false JSON will be returned. Defaults tofalse
APP_DEBUG_TRACE
: If true, stack trace will be included in the application errors. Defaults totrue
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
Here are some of the provided exception classes
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.
Syntactic Sugar
Also, for any of the exception classes above, you can use the below syntax as well.
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.
Contributing
Feel free to fork, enhance, create PR and lock issues.
License
MIT © Kamran Ahmed