private function resolveErrorHandlerFromAcceptHeader(Request $request): callable
    {
        // Try to find an error handler for one of the accepted content types
        $accepts = $request->hasHeader('Accept') ? $request->getHeaderLine('Accept') : $this->defaultContentType;
        /** @var array $accepts */
        $accepts = explode(',', $accepts);
        foreach ($accepts as $accept) {
            if (! $this->errorHandlerManager->has($accept)) {
                continue;
            }

            return $this->errorHandlerManager->get($accept);
        }

        // If it wasn't possible to find an error handler for accepted content type, use default one if registered
        if ($this->errorHandlerManager->has($this->defaultContentType)) {
            return $this->errorHandlerManager->get($this->defaultContentType);
        }

        // It wasn't possible to find an error handler
        throw new InvalidArgumentException(sprintf(
            'It wasn\'t possible to find an error handler for ["%s"] content types. '
            . 'Make sure you have registered at least the default "%s" content type',
            implode('", "', $accepts),
            $this->defaultContentType
        ));
    }
private function resolveErrorHandlerFromAcceptHeader(Request $request): callable
    {
        // Try to find an error handler for one of the accepted content types
        $accepts = $request->hasHeader('Accept') ? $request->getHeaderLine('Accept') : $this->defaultContentType;
        /** @var array $accepts */
        $accepts = explode(',', $accepts);
        foreach ($accepts as $accept) {
            if (! $this->errorHandlerManager->has($accept)) {
                continue;
            }

            return $this->errorHandlerManager->get($accept);
        }

        // If it wasn't possible to find an error handler for accepted content type, use default one if registered
        if ($this->errorHandlerManager->has($this->defaultContentType)) {
            return $this->errorHandlerManager->get($this->defaultContentType);
        }

        // It wasn't possible to find an error handler
        throw new InvalidArgumentException(sprintf(
            'It wasn\'t possible to find an error handler for ["%s"] content types. '
            . 'Make sure you have registered at least the default "%s" content type',
            implode('", "', $accepts),
            $this->defaultContentType
        ));
    }
private function resolveErrorHandlerFromAcceptHeader ( Request $ request ) : callable { // Try to find an error handler for one of the accepted content types $ accepts = $ request -> hasHeader ( 'Accept' ) ? $ request -> getHeaderLine ( 'Accept' ) : $ this -> defaultContentType ; /** @var array $accepts */ $ accepts = explode ( ',' , $ accepts ) ; foreach ( $ accepts as $ accept ) { if ( ! $ this -> errorHandlerManager -> has ( $ accept ) ) { continue ; } return $ this -> errorHandlerManager -> get ( $ accept ) ; } // If it wasn't possible to find an error handler for accepted content type, use default one if registered if ( $ this -> errorHandlerManager -> has ( $ this -> defaultContentType ) ) { return $ this -> errorHandlerManager -> get ( $ this -> defaultContentType ) ; } // It wasn't possible to find an error handler throw new InvalidArgumentException ( sprintf ( 'It wasn\'t possible to find an error handler for ["%s"] content types. ' . 'Make sure you have registered at least the default "%s" content type' , implode ( '", "' , $ accepts ) , $ this -> defaultContentType ) ) ; }
Tries to resolve an error response generator based on request's accept header

@param Request $request
@return callable
@throws InvalidArgumentException
Tries to resolve an error response generator based on request s accept header