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
+18-11Lines changed: 18 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -31,7 +31,7 @@ We aim to support versions that haven't reached their end-of-life.
31
31
composer require attributes-php/wp-exceptions
32
32
```
33
33
34
-
## Docs
34
+
## How it works?
35
35
36
36
Once the ExceptionHandler is registered, you can start throwing exceptions
37
37
@@ -41,11 +41,12 @@ use Attributes\Wp\Exceptions\ExceptionHandler;
41
41
ExceptionHandler::register();
42
42
```
43
43
44
-
### How *HttpExceptions* are displayed?
44
+
<details>
45
+
<summary><h4>How <b>HttpExceptions</b> are displayed?</h4></summary>
45
46
46
-
WordPress itself handles how an [*HttpException*](https://github.com/Attributes-PHP/wp-exceptions/blob/main/src/HttpException.php) is displayed to the user.
47
-
In a nutshell, those exceptions are converted into a [*WP_Error*](https://developer.wordpress.org/reference/classes/wp_error/)
48
-
which is then handled by WordPress via [*wp_die*](https://developer.wordpress.org/reference/functions/wp_die/) function.
47
+
WordPress itself handles how an <ahref="https://github.com/Attributes-PHP/wp-exceptions/blob/main/src/HttpException.php"target="_blank"><b>HttpException</b></a>
48
+
is displayed to the user. In a nutshell, those exceptions are converted into a <ahref="https://developer.wordpress.org/reference/classes/wp_error/"target="_blank"><b>WP_Error</b></a>
49
+
which is then handled by WordPress via <ahref="https://developer.wordpress.org/reference/functions/wp_die/"target="_blank"><i>wp_die</i></a> function.
49
50
50
51
This means, that the following types of requests are supported:
51
52
@@ -55,26 +56,31 @@ This means, that the following types of requests are supported:
55
56
- ✅ XMLRPC
56
57
- ✅ XML
57
58
- ✅ All other types e.g. HTML
59
+
</details>
58
60
59
-
### How to send custom HTTP headers?
61
+
<details>
62
+
<summary><h4>How to send custom HTTP headers?</h4></summary>
60
63
61
64
```php
62
65
throw new HttpException(400, 'My message', headers: ['My-Header' => 'Value 123']);
63
66
```
67
+
</details>
64
68
65
-
### How to add custom handlers?
69
+
<details>
70
+
<summary><h4>How to add custom handlers?</h4></summary>
$exceptionHandler->onException(CustomException::class, fn($ex) => echo "A custom exception has been raised");
70
75
```
71
76
72
-
> [!TIP]
73
-
> Add a handler which supports all types of possible requests e.g. REST, XML, etc
77
+
Ensure to add handlers which supports all types of possible requests e.g. JSON, XML, etc
78
+
</details>
74
79
75
-
### Sage theme support
80
+
<details>
81
+
<summary><h4>Sage theme support</h4></summary>
76
82
77
-
If you are using [Sage](https://github.com/roots/sage) theme, you would need to register or re-register
83
+
If you are using <ahref="https://github.com/roots/sage"target="_blank"><i>Sage</i></a> theme, you would need to register or re-register
78
84
this exception handler after the application is configured. Otherwise, this exception handler might be overrided.
79
85
80
86
```php
@@ -88,5 +94,6 @@ Application::configure()
88
94
89
95
ExceptionHandler::register(force: true); // We are using force true in case the ExceptionHandler has been registered before e.g. in a plugin
90
96
```
97
+
</details>
91
98
92
99
WP Exceptions was created by **[André Gil](https://www.linkedin.com/in/andre-gil/)** and is open-sourced software licensed under the **[MIT license](https://opensource.org/licenses/MIT)**.
0 commit comments