Skip to content

Commit 417e609

Browse files
committed
Added preview
1 parent 66a6c94 commit 417e609

File tree

2 files changed

+27
-32
lines changed

2 files changed

+27
-32
lines changed

LICENCE renamed to LICENSE

File renamed without changes.

README.md

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
[![Total Downloads](https://img.shields.io/packagist/dt/samuelgfeller/slim-error-renderer.svg)](https://packagist.org/packages/samuelgfeller/slim-error-renderer/stats)
77

88
This package provides an alternative to the default Slim error handler and renderer.
9-
It renders a styled [error details page](#error-details-design) with the stack trace and the error message
10-
or a [generic error page](#generic-error-page-design) for production.
9+
It renders a styled error details page with the stack trace and the error message
10+
or a generic error page for production.
1111

1212
Custom error page renderers can be created to change the design of the error pages
1313
by implementing the `ErrorDetailsPageRendererInterface`
@@ -17,26 +17,11 @@ It also provides a [middleware](#exception-heavy-middleware) to make the project
1717
which means that it will throw exceptions with a stack trace for notices and warnings during
1818
development and testing like other frameworks such as Laravel or Symfony.
1919

20-
## Why use this package?
21-
22-
A reason this small library exists instead of using the default Slim error handler and a [custom
23-
error renderer](https://www.slimframework.com/docs/v4/middleware/error-handling.html#error-handlingrendering),
24-
is to provide the "exception-heavy" feature and better-looking error pages.
25-
But these things can be achieved with a custom error renderer and middleware located in the project as well.
20+
## Preview
2621

27-
The issue with the default `Slim\Handlers\ErrorHandler` is that while testing, the
28-
`$contentType` in the error handler is `null` and instead of using any custom error renderer
29-
its hardcoded to use the `Slim\Error\Renderers\HtmlErrorRenderer`. This has two consequences:
30-
31-
1. The error is not thrown while integration testing, which means debugging is harder.
32-
2. Tests where an exception is expected, fail with the
33-
[PHPUnit 11 warning](tps://github.com/sebastianbergmann/phpunit/pull/5619)
34-
`Test code or tested code did not remove its own error handlers`.
35-
A fix for this message is calling `restore_error_handler()` but this can't be done as the error handler doesn't
36-
allow for custom error renderers when testing.
37-
38-
So a custom handler is required anyway, and with the custom renderers and the handling of
39-
non-fatal errors, it made sense to put that in a separate small library.
22+
| Exception | Warning and Notice | Generic error page |
23+
|-----------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------|
24+
| <img src="https://github.com/samuelgfeller/slim-error-renderer/assets/31797204/ef88013f-841f-417b-8626-6c1fc4d38a8b"> | <img src="https://github.com/samuelgfeller/slim-example-project/assets/31797204/9c2e3d7c-6752-4854-b535-5e54d25fd11e"> | <img src="https://github.com/samuelgfeller/slim-example-project/assets/31797204/d1fd052e-a16f-4a76-895a-2eac456c4a79"> |
4025

4126
## Requirements
4227

@@ -55,11 +40,14 @@ composer require samuelgfeller/slim-error-renderer
5540
```
5641

5742
### Configuration
43+
5844
The following configuration values are required in the settings.
59-
[Modify accordingly](https://github.com/samuelgfeller/slim-example-project/wiki/Error-Handling#application-configuration)
60-
in the development, production, and testing configuration files.
45+
Modify accordingly
46+
in the development, production, and testing
47+
[configuration files](https://github.com/samuelgfeller/slim-example-project/wiki/Error-Handling#application-configuration).
6148

6249
File: `config/defaults.php`
50+
6351
```php
6452
$settings['error'] = [
6553
// Must be set to false in production
@@ -206,16 +194,23 @@ implementation of this package and the
206194
[`slim-example-project`](https://github.com/samuelgfeller/slim-example-project) for a custom
207195
generic error page rendering with layout.
208196

209-
## Error details design
210-
211-
### Fatal error
212-
213-
<img src="https://github.com/samuelgfeller/slim-example-project/assets/31797204/fea0abee-17f6-46dd-9efa-c5928244f7b6" width="600">
197+
## Why use this package?
214198

215-
### Warning / Notice
199+
A reason this small library exists instead of using the default Slim error handler and a [custom
200+
error renderer](https://www.slimframework.com/docs/v4/middleware/error-handling.html#error-handlingrendering),
201+
is to provide the "exception-heavy" feature and better-looking error pages.
202+
But these things can be achieved with a custom error renderer and middleware located in the project as well.
216203

217-
<img src="https://github.com/samuelgfeller/slim-example-project/assets/31797204/9c2e3d7c-6752-4854-b535-5e54d25fd11e" width="600">
204+
The issue with the default `Slim\Handlers\ErrorHandler` is that while testing, the
205+
`$contentType` in the error handler is `null` and instead of using any custom error renderer
206+
its hardcoded to use the `Slim\Error\Renderers\HtmlErrorRenderer`. This has two consequences:
218207

219-
## Generic error page design
208+
1. The error is not thrown while integration testing, which means debugging is harder.
209+
2. Tests where an exception is expected, fail with the
210+
[PHPUnit 11 warning](tps://github.com/sebastianbergmann/phpunit/pull/5619)
211+
`Test code or tested code did not remove its own error handlers`.
212+
A fix for this message is calling `restore_error_handler()` but this can't be done as the error handler doesn't
213+
allow for custom error renderers when testing.
220214

221-
<img src="https://github.com/samuelgfeller/slim-example-project/assets/31797204/d1fd052e-a16f-4a76-895a-2eac456c4a79" width="600">
215+
So a custom handler is required anyway, and with the custom renderers and the handling of
216+
non-fatal errors, it made sense to put that in a separate small library.

0 commit comments

Comments
 (0)