Skip to content

Commit b716cbc

Browse files
committed
docs: Add how it works section to README
1 parent ed2671d commit b716cbc

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

README.md

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ We aim to support versions that haven't reached their end-of-life.
3131
composer require attributes-php/wp-exceptions
3232
```
3333

34-
## Docs
34+
## How it works?
3535

3636
Once the ExceptionHandler is registered, you can start throwing exceptions
3737

@@ -41,11 +41,12 @@ use Attributes\Wp\Exceptions\ExceptionHandler;
4141
ExceptionHandler::register();
4242
```
4343

44-
### How *HttpExceptions* are displayed?
44+
<details>
45+
<summary><h4>How <b>HttpExceptions</b> are displayed?</h4></summary>
4546

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 <a href="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 <a href="https://developer.wordpress.org/reference/classes/wp_error/" target="_blank"><b>WP_Error</b></a>
49+
which is then handled by WordPress via <a href="https://developer.wordpress.org/reference/functions/wp_die/" target="_blank"><i>wp_die</i></a> function.
4950

5051
This means, that the following types of requests are supported:
5152

@@ -55,26 +56,31 @@ This means, that the following types of requests are supported:
5556
- ✅ XMLRPC
5657
- ✅ XML
5758
- ✅ All other types e.g. HTML
59+
</details>
5860

59-
### How to send custom HTTP headers?
61+
<details>
62+
<summary><h4>How to send custom HTTP headers?</h4></summary>
6063

6164
```php
6265
throw new HttpException(400, 'My message', headers: ['My-Header' => 'Value 123']);
6366
```
67+
</details>
6468

65-
### How to add custom handlers?
69+
<details>
70+
<summary><h4>How to add custom handlers?</h4></summary>
6671

6772
```php
6873
$exceptionHandler = ExceptionHandler::getInstance();
6974
$exceptionHandler->onException(CustomException::class, fn($ex) => echo "A custom exception has been raised");
7075
```
7176

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>
7479

75-
### Sage theme support
80+
<details>
81+
<summary><h4>Sage theme support</h4></summary>
7682

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 <a href="https://github.com/roots/sage" target="_blank"><i>Sage</i></a> theme, you would need to register or re-register
7884
this exception handler after the application is configured. Otherwise, this exception handler might be overrided.
7985

8086
```php
@@ -88,5 +94,6 @@ Application::configure()
8894

8995
ExceptionHandler::register(force: true); // We are using force true in case the ExceptionHandler has been registered before e.g. in a plugin
9096
```
97+
</details>
9198

9299
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

Comments
 (0)