|
2 | 2 |
|
3 | 3 | # **`Part of Queen Packages 👑`** |
4 | 4 |
|
5 | | -[](https://pub.dev/packages/lint) |
6 | | - |
7 | 5 | # Motivation |
8 | 6 |
|
9 | 7 | - since we work with APIs built with `Laravel` almost daily |
10 | | -- i have built this package to easily wrap the validation exception which laravel might throw |
11 | | -- you can easily know which fields got rejected or have failed and there messages |
| 8 | +- i have built this package to easily wrap the validation , NotFound , Internal Server Error exceptions which laravel might throw |
| 9 | +- you can easily know which fields got rejected or have failed and there messages in case of validation |
| 10 | +- in laravel debug mode extract the message easily with the stack trace |
| 11 | +- also you can build your custom exception if needed |
12 | 12 |
|
13 | 13 | # Content |
14 | 14 |
|
15 | | -- `LaravelException` Exception class which will parse the laravel response |
| 15 | +- `LaravelException` abstract class which will parse the laravel response |
| 16 | +- `LValidationException` Exception for `422` status code use the constructor to create objects |
| 17 | +- `LServerException` Exception for `500` status code use the `parse(Map)` factory to create objects |
| 18 | +- `LNotFoundException` Exception for `404` status code use the `parse(Map)` factory to create objects |
16 | 19 |
|
17 | 20 | # example |
18 | 21 |
|
19 | 22 | ```dart |
20 | | - // 422 |
21 | | -if(res.statusCode == HttpStatus.unprocessableEntity){ |
22 | | - throw LaravelException.parse(res.data); |
| 23 | +
|
| 24 | +if(res.statusCode == 422){ |
| 25 | + throw LValidationException(res.data); |
| 26 | +}else if(res.statusCode == 500){ |
| 27 | + throw LServerException.parse(res.data); |
| 28 | +}else if(res.statusCode == 404){ |
| 29 | + throw LNotFoundException.parse(res.data); |
23 | 30 | } |
24 | 31 |
|
25 | 32 | ``` |
26 | 33 |
|
27 | | -# Exception props 🧬 |
28 | | - |
29 | | -- `keys` contains the failed input keys in the exception object |
30 | | -- `errorMessages` contains the failed input keys in the exception object |
31 | | -- `firstErrorMessage` return the first failure message |
32 | | -- `toString()` convert the object to one big error message |
33 | | - |
34 | 34 | # What is next ? |
35 | 35 |
|
36 | 36 | - [ ] dio interceptor |
|
0 commit comments