Symfony/API Platform Error Listeners

Useful when change the error response format (e.g. change type in HTTP Problem Details RFC 7807)

Symfony Exception Listener

bin/console debug:container exception_listener --show-arguments

Information for Service "exception_listener"
============================================

 ---------------- ---------------------------------------------------------- 
  Option           Value                                                     
 ---------------- ---------------------------------------------------------- 
  Service ID       exception_listener                                        
  Class            Symfony\Component\HttpKernel\EventListener\ErrorListener  
  Tags             kernel.event_subscriber                                   
                   monolog.logger (channel: request)                         
                   container.hot_path                                        
                   container.hot_path                                        
  Public           no                                                        
  Synthetic        no                                                        
  Lazy             no                                                        
  Shared           yes                                                       
  Abstract         no                                                        
  Autowired        no                                                        
  Autoconfigured   no                                                        
  Arguments        error_controller                                          
                   Service(monolog.logger.request)                           
                   1                                                         
                   Array (0 element(s))                                      
 ---------------- ----------------------------------------------------------

Symfony Error Controller

$ bin/console debug:container error_controller                   

Information for Service "error_controller"
==========================================

 Renders error or exception pages from a given FlattenException.

 ---------------- --------------------------------------------------------- 
  Option           Value                                                    
 ---------------- --------------------------------------------------------- 
  Service ID       error_controller                                         
  Class            Symfony\Component\HttpKernel\Controller\ErrorController  
  Tags             -                                                        
  Public           yes                                                      
  Synthetic        no                                                       
  Lazy             no                                                       
  Shared           yes                                                      
  Abstract         no                                                       
  Autowired        no                                                       
  Autoconfigured   no                                                       
 ---------------- ---------------------------------------------------------

API Platform Exception Listener

This exception listener's priority is higher than the Symfony default one.

If (_api_respond is true or _graphql is true) and requested format is not html, it will call API Platform's error controller instead of propagate down to the Symfony default exception listener, which calls Symfony's default error controller.

$ bin/console debug:container api_platform.listener.exception --show-arguments

Information for Service "api_platform.listener.exception"
=========================================================

 Handles requests errors.

 ---------------- ------------------------------------------------------------------------------------------- 
  Option           Value                                                                                      
 ---------------- ------------------------------------------------------------------------------------------- 
  Service ID       api_platform.listener.exception                                                            
  Class            ApiPlatform\Core\EventListener\ExceptionListener                                           
  Tags             kernel.event_listener (event: kernel.exception, method: onKernelException, priority: -96)  
                   monolog.logger (channel: request)                                                          
  Public           no                                                                                         
  Synthetic        no                                                                                         
  Lazy             no                                                                                         
  Shared           yes                                                                                        
  Abstract         no                                                                                         
  Autowired        no                                                                                         
  Autoconfigured   no                                                                                         
  Arguments        api_platform.action.exception                                                              
                   Service(monolog.logger.request)                                                            

                   Service(exception_listener)                                                                
 ---------------- -------------------------------------------------------------------------------------------

API Platform Error Controller

If the requested content type matches one of the configured error formats, it will be used. Otherwise the first error format will be used as default format.

$ bin/console debug:container api_platform.action.exception --show-arguments

Information for Service "api_platform.action.exception"
=======================================================

 Renders a normalized exception for a given {@see FlattenException} or {@see LegacyFlattenException}.

 ---------------- ----------------------------------------- 
  Option           Value                                    
 ---------------- ----------------------------------------- 
  Service ID       api_platform.action.exception            
  Class            ApiPlatform\Core\Action\ExceptionAction  
  Tags             -                                        
  Public           yes                                      
  Synthetic        no                                       
  Lazy             no                                       
  Shared           yes                                      
  Abstract         no                                       
  Autowired        no                                       
  Autoconfigured   no                                       
  Arguments        Service(serializer)                      
                   %api_platform.error_formats%             
                   %api_platform.exception_to_status%       
 ---------------- -----------------------------------------

API Platform Validation Error Listener

$ bin/console debug:container api_platform.listener.exception.validation --show-arguments

Information for Service "api_platform.listener.exception.validation"
====================================================================

 Handles validation errors.

 ---------------- ------------------------------------------------------------------------------------- 
  Option           Value                                                                                
 ---------------- ------------------------------------------------------------------------------------- 
  Service ID       api_platform.listener.exception.validation                                           
  Class            ApiPlatform\Core\Bridge\Symfony\Validator\EventListener\ValidationExceptionListener  
  Tags             kernel.event_listener (event: kernel.exception, method: onKernelException)           
  Public           no                                                                                   
  Synthetic        no                                                                                   
  Lazy             no                                                                                   
  Shared           yes                                                                                  
  Abstract         no                                                                                   
  Autowired        no                                                                                   
  Autoconfigured   no                                                                                   
  Arguments        Service(serializer)                                                                  
                   %api_platform.error_formats%                                                         
                   %api_platform.exception_to_status%                                                   
 ---------------- -------------------------------------------------------------------------------------

kernel.request

  • ApiPlatform\Core\Bridge\Symfony\Bundle\EventListener\SwaggerUiListener If _api_respond is true and no resource class set and requested format is HTML then render swagger UI