https://github.com/yiisoft/friendly-exception
An interface for an exception to be friendly
https://github.com/yiisoft/friendly-exception
error-handling exception exceptions friendly hacktoberfest yii3
Last synced: 2 months ago
JSON representation
An interface for an exception to be friendly
- Host: GitHub
- URL: https://github.com/yiisoft/friendly-exception
- Owner: yiisoft
- License: bsd-3-clause
- Created: 2019-09-20T15:32:45.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-05-18T14:24:33.000Z (about 1 year ago)
- Last Synced: 2024-10-29T14:35:39.970Z (7 months ago)
- Topics: error-handling, exception, exceptions, friendly, hacktoberfest, yii3
- Language: PHP
- Homepage: https://www.yiiframework.com/
- Size: 62.5 KB
- Stars: 48
- Watchers: 20
- Forks: 8
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: .github/CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE.md
- Code of conduct: .github/CODE_OF_CONDUCT.md
- Security: .github/SECURITY.md
Awesome Lists containing this project
README
Yii Friendly Exception
[](https://packagist.org/packages/yiisoft/friendly-exception)
[](https://packagist.org/packages/yiisoft/friendly-exception)An exception interface that provides a friendly name and a possible solution.
Error handlers may consider the interface to render additional information right at the error screen.## Requirements
- PHP 7.4 or higher.
## Installation
The package could be installed with [Composer](https://getcomposer.org):
```shell
composer require yiisoft/friendly-exception
```## General usage
### Implementing friendly exception
To make exception friendly require this package and implement `FriendlyExceptionInterface`:
```php
use Yiisoft\FriendlyException\FriendlyExceptionInterface;class RequestTimeoutException extends \RuntimeException implements FriendlyExceptionInterface
{
public function getName(): string
{
return 'Request timed out.';
}
public function getSolution(): ?string
{
return <<<'SOLUTION'
Likely it is a result of resource request is not responding in a timely fashion. Try increasing timeout.
SOLUTION;
}
}
```When returning solution consider the following best practices:
1. Make solution description as short as possible.
2. Do not use HTML tags.
3. Use [simple markdown](https://commonmark.org/help/).### Handling friendly exception
To make your exception handler render friendly exceptions:
```php
use Yiisoft\FriendlyException\FriendlyExceptionInterface;class ThrowableHandler
{
public function handle(\Throwable $t)
{
if ($t instanceof FriendlyExceptionInterface) {
// additional handling
}
// regular handling
}
}
```Do not forget to [render markdown](https://github.com/commonmark/commonmark-spec/wiki/List-of-CommonMark-Implementations#php).
## Documentation
- [Internals](docs/internals.md)
If you need help or have a question, the [Yii Forum](https://forum.yiiframework.com/c/yii-3-0/63) is a good place for that.
You may also check out other [Yii Community Resources](https://www.yiiframework.com/community).## License
The Yii Friendly Exception is free software. It is released under the terms of the BSD License.
Please see [`LICENSE`](./LICENSE.md) for more information.Maintained by [Yii Software](https://www.yiiframework.com/).
## Support the project
[](https://opencollective.com/yiisoft)
## Follow updates
[](https://www.yiiframework.com/)
[](https://twitter.com/yiiframework)
[](https://t.me/yii3en)
[](https://www.facebook.com/groups/yiitalk)
[](https://yiiframework.com/go/slack)