f1monkey / request-handle-bundle
Common request deserialization and exception handling
Installs: 46
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: ^7.4
- ext-json: *
- doctrine/collections: ^1.6
- jms/serializer-bundle: ^3.6
- symfony/dependency-injection: ^5.0
- symfony/framework-bundle: ^5.0
- symfony/http-kernel: ^5.0
- symfony/translation: ^5.1
- symfony/validator: ^5.0
Requires (Dev)
- codeception/codeception: ^4.1
- codeception/module-asserts: ^1.2
- codeception/module-cli: ^1.0
- codeception/module-phpbrowser: ^1.0
- codeception/module-rest: ^1.2
- codeception/module-symfony: ^1.1
- phpstan/phpstan: ^0.12.29
- symfony/monolog-bundle: ^3.5
- symfony/yaml: ^5.1
This package is auto-updated.
Last update: 2021-08-29 02:17:07 UTC
README
- RequestDeserializationValueResolver argument value resolver to deserialize request parameters using jms-serializer
- RequestValidationListener to validate request. Returns HTTP 400 response on validation error
- ExceptionListener to handle application exceptions and transform them to HTTP errors
- ExceptionLogListener to log application exceptions
Installation
$ composer require f1monkey/request-handle-bundle
Add to config/bundles.php
:
<?php return [ // ... F1Monkey\RequestHandleBundle\RequestHandleBundle::class => ['all' => true], ];
Create config file (i.e. config/packages/request_handle.yaml
)
Configuration
request_handle: value_resolver: # controller arguments implementing this interface will be deserialized using RequestDeserializationValueResolver request_class: App\Model\RequestInterface request_validator: # controller arguments implementing this interface will be validated using RequestValidationListener request_class: App\Model\RequestInterface exception_log: # logger service id for exception logging (default value = @logger) logger: 'logger'
ExceptionListener
Custom error response
If you need to customize error response, you should override exception response factory in your application's services.yaml
services: F1Monkey\RequestHandleBundle\Factory\ErrorResponseFactoryInterface: class: App\Factory\ErrorResponseFactory
Custom exception message
By default, error messages are overridden by default HTTP messages according to HTTP response code. To set a custom error message, you should implement UserFriendlyExceptionInterface in your Exception class.
X-Debug header
Because all exceptions are transformed to a "user-friendly" responses, debugging becomes harder: symfony error page will not appear at all. To show the error page, two conditions must be met:
kernel.debug
parameter set totrue
(it is default setting fordev
environment)X-Debug
header is present in the request
ExceptionLogListener
Customize logging
To customize logging you should override logger context provider service:
services: F1Monkey\RequestHandleBundle\Service\LogContextProviderInterface: class: App\Service\LogContextProvider