Download the PHP package tounaf/exception-bundle without Composer
On this page you can find all versions of the php package tounaf/exception-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download tounaf/exception-bundle
More information about tounaf/exception-bundle
Files in tounaf/exception-bundle
Package exception-bundle
Short Description Exception handler for symfony project
License MIT
Informations about the package exception-bundle
If you need to manage complexe exception in your application, this bundle is set for you . This bundle provides interface to facilitate the customization of the exception rendering in Symfony project. Each exception that you create has his own handler classe. Your exception will be scalable, maintenable, independent.
1 - Installation
2 - How to work
By default, this bundle handle exception and render a json response but you can customize this behavior with your needs (ex: html)
3 - Create custom execption handler
Create an class and implement the PulseExceptionInteface interface. It contains two methods:
** handleException: This method have Throwble as argument and returns a Symfony Response
** supportsException: This method have Throwble as argument and return boolean.
Example:
First create Exception to handle through the app.
Then create the handler that handle this exception
When MyException is thrown, the MyExceptionHandler class is called by the system . For example:
3 - Format Response
Sometimes, your app provides the service that third party can consume: for example :
but the uri
An HandlerException can provide multiple format of response like html, json, etc.
By default, this bundle supports html and json for format of response but it is extensible to create custom
format like json-ld, xml etc.
To do that, you need to implement the interface Tounaf\ExceptionBundle\FormatResponse\FormatResponseCheckerInterface.
This interface have a method setFormat(FormatResponseInterface $formatResponse) that accepts FormatResponseInterface as argument.
What happen with this code ? As said at the top, this bundle provides two responses by default : html and json. Which of these formats on this code ? For the URI that match /api/, the response used is json else html is rendered.
All versions of exception-bundle with dependencies
symfony/config Version 6.4.* || 6.3.* || 6.2.* || 6.1.* || 5.4.* || 4.4.*
symfony/framework-bundle Version 6.4.* || 6.3.* || 6.2.* || 6.1.* || 5.4.* || 4.4.*
symfony/http-kernel Version 6.4.* || 6.3.* || 6.2.* || 6.1.* || 5.4.* || 4.4.*
tounaf/exception-handler Version ^1.4