You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+36-22Lines changed: 36 additions & 22 deletions
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,8 @@
1
1
# Laravel Faulty - RESTful Exceptions
2
2
3
-
A Laravel/Lumen package that lets you handle the API problems with ease. All the thrown exceptions HTTP or non-HTTP are properly rendered as JSON.
3
+
> Automatically turns your thrown exceptions (HTTP/non-HTTP) to the JSON response while conforming to API problem specification.
4
+
5
+
A Laravel/Lumen package that lets you handle the API problems with ease.
4
6
5
7
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`
6
8
@@ -20,44 +22,51 @@ Where
20
22
-`detail` is human readable explanation specific to problem
21
23
-`instance` is the absolute URI that identifies the specific occurrence of the problem
22
24
23
-
> Faulty automatically turns your thrown exceptions to the specified response.
24
-
25
25
## Installation
26
26
27
27
Run the below command
28
+
28
29
```
29
30
composer require kamranahmedse/laravel-faulty
30
31
```
31
32
32
33
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.
33
34
34
-
```
35
-
\KamranAhmed\Faulty\Handler
36
-
```
37
-
38
-
And that's it. You are all set to use Faulty.
35
+
```php
36
+
37
+
use KamranAhmed\Faulty\Handler as FaultyHandler;
38
+
39
+
class Handler extends FaultyHandler {
40
+
// ...
41
+
}
42
+
```
39
43
40
-
## Configuration
41
-
Faulty relies on the following environment configurations
44
+
And that's it. You are all set to use Faulty.
42
45
43
-
-`APP_DEBUG` : If `true`, exceptions will be rendered with whoops, if false JSON will be returned. **Defaults to `false`**
44
-
-`APP_DEBUG_TRACE` : If true, stack trace will be included in the application errors. **Defaults to `true`**
46
+
##Configuration
47
+
Faulty relies on the following environment configurations
48
+
49
+
-`APP_DEBUG` : If `true`, exceptions will be rendered with whoops, if false JSON will be returned. **Defaults to `false`**
50
+
-`APP_DEBUG_TRACE` : If true, stack trace will be included in the application errors. **Defaults to `true`**
45
51
46
-
## Usage
52
+
## Usage
47
53
48
-
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`
54
+
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`
49
55
50
-
#### Throwing Exceptions
51
-
All the exception classes have the below signature
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.
0 commit comments