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: docs/book/v4/core-features/exceptions.md
+26-9Lines changed: 26 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,28 +10,43 @@ They provide a way to manage errors in a structured and controlled manner, separ
10
10
When it comes to handling exceptions, DotKernel API relies on the usage of easy-to-understand, problem-specific exceptions.
11
11
12
12
Ou-of-the-box we provide the following custom exceptions:
13
+
13
14
*`BadRequestException` thrown when:
14
-
* client tries to create/update resource, but the data from the request is invalid/incomplete (example: client tries to create an account, but does not send the required `identity` field)
15
+
16
+
1. client tries to create/update resource, but the data from the request is invalid/incomplete (example: client tries to create an account, but does not send the required `identity` field)
17
+
15
18
*`ConflictException` thrown when:
16
-
* resource cannot be created because a different resource with the same identifier already exists (example: cannot change existing user's identity because another user with the same identity already exists)
17
-
* resource cannot change its state because it is already in the specified state (example: user cannot be activated because it is already active)
19
+
20
+
1. resource cannot be created because a different resource with the same identifier already exists (example: cannot change existing user's identity because another user with the same identity already exists)
21
+
2. resource cannot change its state because it is already in the specified state (example: user cannot be activated because it is already active)
22
+
18
23
*`ExpiredException` thrown when:
19
-
* resource cannot be accessed because it expired (example: account activation link)
20
-
* resource cannot be accessed because it has been consumed (example: one-time password)
24
+
25
+
1. resource cannot be accessed because it expired (example: account activation link)
26
+
2. resource cannot be accessed because it has been consumed (example: one-time password)
27
+
21
28
*`ForbiddenException` thrown when:
22
-
* resource cannot be accessed by the authenticated client (example: client authenticated as regular user sends a `GET /admin` request)
29
+
30
+
1. resource cannot be accessed by the authenticated client (example: client authenticated as regular user sends a `GET /admin` request)
31
+
23
32
*`MethodNotAllowedException` thrown when:
24
-
* client tries to interact with a resource via an invalid HTTP request method (example: client sends a `PATCH /avatar` request)
33
+
34
+
1. client tries to interact with a resource via an invalid HTTP request method (example: client sends a `PATCH /avatar` request)
35
+
25
36
*`NotFoundException` thrown when:
26
-
* client tries to interact with a resource that does not exist on the server (example: client sends a `GET /resource-does-not-exist` request)
37
+
38
+
1. client tries to interact with a resource that does not exist on the server (example: client sends a `GET /resource-does-not-exist` request)
39
+
27
40
*`UnauthorizedException` thrown when:
28
-
* resource cannot be accessed because the client is not authenticated (example: unauthenticated client sends a `GET /admin` request)
41
+
42
+
1. resource cannot be accessed because the client is not authenticated (example: unauthenticated client sends a `GET /admin` request)
29
43
30
44
## How it works?
31
45
32
46
During a request, if there is no uncaught exception DotKernel API will return a JSON response with the data provided by the handler that handled the request.
33
47
34
48
Else, it will build and send a response based on the exception thrown:
49
+
35
50
*`BadRequestException` will return a `400 Bad Request` response
36
51
*`UnauthorizedException` will return a `401 Unauthorized` response
37
52
*`ForbiddenException` will return a `403 Forbidden` response
@@ -63,6 +78,7 @@ class CustomException extends Exception
63
78
{
64
79
}
65
80
```
81
+
66
82
Save and close the file.
67
83
68
84
### Step 2: Use exception file
@@ -72,6 +88,7 @@ Open the file `src/App/src/Handler/HomeHandler.php` and at the beginning of the
72
88
```php
73
89
throw new \Api\App\Exception\CustomException('some message');
0 commit comments