private function generateExceptionResponse($request, Exception $e)
    {
        $formatters = $this->config['formatters'];

        // :: notation will otherwise not work for PHP <= 5.6
        $responseFactoryClass = $this->config['response_factory'];

        // Allow users to have a base formatter for every response.
        $response = $responseFactoryClass::make($e);

        foreach($formatters as $exceptionType => $formatter) {
            if (!($e instanceof $exceptionType)) {
                continue;
            }

            if (
                !class_exists($formatter) ||
                !(new ReflectionClass($formatter))->isSubclassOf(new ReflectionClass(BaseFormatter::class))
            ) {
                throw new InvalidArgumentException(
                    sprintf(
                        "%s is not a valid formatter class.",
                        $formatter
                    )
                );
            }

            $formatterInstance = new $formatter($this->config, $this->debug);
            $formatterInstance->format($response, $e, $this->reportResponses);

            break;
        }

        return $response;
    }
private function generateExceptionResponse($request, Exception $e)
    {
        $formatters = $this->config['formatters'];

        // :: notation will otherwise not work for PHP <= 5.6
        $responseFactoryClass = $this->config['response_factory'];

        // Allow users to have a base formatter for every response.
        $response = $responseFactoryClass::make($e);

        foreach($formatters as $exceptionType => $formatter) {
            if (!($e instanceof $exceptionType)) {
                continue;
            }

            if (
                !class_exists($formatter) ||
                !(new ReflectionClass($formatter))->isSubclassOf(new ReflectionClass(BaseFormatter::class))
            ) {
                throw new InvalidArgumentException(
                    sprintf(
                        "%s is not a valid formatter class.",
                        $formatter
                    )
                );
            }

            $formatterInstance = new $formatter($this->config, $this->debug);
            $formatterInstance->format($response, $e, $this->reportResponses);

            break;
        }

        return $response;
    }
private function generateExceptionResponse ( $ request , Exception $ e ) { $ formatters = $ this -> config [ 'formatters' ] ; // :: notation will otherwise not work for PHP <= 5.6 $ responseFactoryClass = $ this -> config [ 'response_factory' ] ; // Allow users to have a base formatter for every response. $ response = $ responseFactoryClass :: make ( $ e ) ; foreach ( $ formatters as $ exceptionType => $ formatter ) { if ( ! ( $ e instanceof $ exceptionType ) ) { continue ; } if ( ! class_exists ( $ formatter ) || ! ( new ReflectionClass ( $ formatter ) ) -> isSubclassOf ( new ReflectionClass ( BaseFormatter :: class ) ) ) { throw new InvalidArgumentException ( sprintf ( "%s is not a valid formatter class." , $ formatter ) ) ; } $ formatterInstance = new $ formatter ( $ this -> config , $ this -> debug ) ; $ formatterInstance -> format ( $ response , $ e , $ this -> reportResponses ) ; break ; } return $ response ; }
Generate exception response

@param $request
@param Exception $e
@return mixed
Generate exception response