Skip to content

Commit 9d77570

Browse files
committed
Update readme
1 parent 361cec1 commit 9d77570

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,27 @@ Also it can have `meta` attribute when there is additional info. For example for
6969
For `ValidationApiException`, meta attribute has `errors` object that contains validations errors.
7070
Every attribute of this object is a name of a request parameter to validate to and value is an array of errors with description.
7171

72+
#### Customization
73+
74+
You can customize errors APU response by overriding `formatApiResponse` method in your ExceptionsHandler.
75+
76+
For example if you want to put everything under `error` attribute, you can do it like this:
77+
78+
```php
79+
/**
80+
* Format error message for API response.
81+
*
82+
* @param ApiException $exception
83+
* @return mixed
84+
*/
85+
protected function formatApiResponse(ApiException $exception)
86+
{
87+
return [
88+
'error' => $exception->toArray(),
89+
];
90+
}
91+
```
92+
7293
### Views
7394

7495
Since version 0.3.0 for Laravel 5.3 package can also return html view of the error, if `Accept` header not equals `application/json`.

0 commit comments

Comments
 (0)