Code Monkey home page Code Monkey logo

friendly-exception's Introduction

Yii Friendly Exception


Latest Stable Version Total Downloads

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:

composer require yiisoft/friendly-exception --prefer-dist

General usage

Implementing friendly exception

To make exception friendly require this package and implement FriendlyExceptionInterface:

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.

Handling friendly exception

To make your exception handler render friendly exceptions:

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.

Documentation

Support

If you need help or have a question, the Yii Forum is a good place for that. You may also check out other Yii Community Resources.

Support the project

Open Collective

Follow updates

Official website Twitter Telegram Facebook Slack

License

The Yii Friendly Exception is free software. It is released under the terms of the BSD License. Please see LICENSE for more information.

Maintained by Yii Software.

friendly-exception's People

Contributors

arhell avatar devanych avatar fantom409 avatar luizcmarin avatar roxblnfk avatar rustamwin avatar samdark avatar vitorarantes avatar vjik avatar xepozz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

friendly-exception's Issues

Add markup type

What do you think about to add getMarkupType() to main interface? Exception handlers can handle any markup types and render final HTML with different markup processors.
For example, I like to write exception's solution with Markdown, but vendor can provide exception with heavy HTML or RST or even GFM (Markdown version by Github)

update irc link

What steps will reproduce the problem?

What is the expected result?

What do you get instead?

Additional info

Q A
Version 1.0.?
PHP version
Operating system

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.