src/Application.php
public function registerErrorHandler()
    {
        $whoops = new \Whoops\Run();
        $configuration = $this->getConfiguration();

        if (isset($configuration['debug']) && $configuration['debug']) {
            $whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler());
        } else {
            $whoops->pushHandler(new \Whoops\Handler\CallbackHandler(function ($exception) {
                $this->logger->error($exception->getMessage(), compact('exception'));

                $request = $this->container->get('request');
                $response = $this->container->get('response');
                $view = $this->container->get('view');
                $errorInfo = ['message' => $exception->getMessage()];

                if (is_a($exception, HttpException::class)) {
                    $errorInfo['code'] = $exception->getCode();
                } else {
                    $errorInfo['code'] = 500;
                }

                $headerAccept = $request->getHeader('Accept');
                if (in_array('application/json', $headerAccept)) {
                    $response = $response->withStatus($errorInfo['code']);
                    $response->getBody()->write(json_encode($errorInfo));

                    $response = $response->withHeader('Content-Type', 'application/json');
                } else {
                    $response = $view->render($response, 'error', $errorInfo);
                }

                $this->emitResponse($response);

                return \Whoops\Handler\Handler::DONE;
            }));
        }

        $whoops->register();
    }
public function registerErrorHandler()
    {
        $whoops = new \Whoops\Run();
        $configuration = $this->getConfiguration();

        if (isset($configuration['debug']) && $configuration['debug']) {
            $whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler());
        } else {
            $whoops->pushHandler(new \Whoops\Handler\CallbackHandler(function ($exception) {
                $this->logger->error($exception->getMessage(), compact('exception'));

                $request = $this->container->get('request');
                $response = $this->container->get('response');
                $view = $this->container->get('view');
                $errorInfo = ['message' => $exception->getMessage()];

                if (is_a($exception, HttpException::class)) {
                    $errorInfo['code'] = $exception->getCode();
                } else {
                    $errorInfo['code'] = 500;
                }

                $headerAccept = $request->getHeader('Accept');
                if (in_array('application/json', $headerAccept)) {
                    $response = $response->withStatus($errorInfo['code']);
                    $response->getBody()->write(json_encode($errorInfo));

                    $response = $response->withHeader('Content-Type', 'application/json');
                } else {
                    $response = $view->render($response, 'error', $errorInfo);
                }

                $this->emitResponse($response);

                return \Whoops\Handler\Handler::DONE;
            }));
        }

        $whoops->register();
    }
public function registerErrorHandler ( ) { $ whoops = new \ Whoops \ Run ( ) ; $ configuration = $ this -> getConfiguration ( ) ; if ( isset ( $ configuration [ 'debug' ] ) && $ configuration [ 'debug' ] ) { $ whoops -> pushHandler ( new \ Whoops \ Handler \ PrettyPageHandler ( ) ) ; } else { $ whoops -> pushHandler ( new \ Whoops \ Handler \ CallbackHandler ( function ( $ exception ) { $ this -> logger -> error ( $ exception -> getMessage ( ) , compact ( 'exception' ) ) ; $ request = $ this -> container -> get ( 'request' ) ; $ response = $ this -> container -> get ( 'response' ) ; $ view = $ this -> container -> get ( 'view' ) ; $ errorInfo = [ 'message' => $ exception -> getMessage ( ) ] ; if ( is_a ( $ exception , HttpException :: class ) ) { $ errorInfo [ 'code' ] = $ exception -> getCode ( ) ; } else { $ errorInfo [ 'code' ] = 500 ; } $ headerAccept = $ request -> getHeader ( 'Accept' ) ; if ( in_array ( 'application/json' , $ headerAccept ) ) { $ response = $ response -> withStatus ( $ errorInfo [ 'code' ] ) ; $ response -> getBody ( ) -> write ( json_encode ( $ errorInfo ) ) ; $ response = $ response -> withHeader ( 'Content-Type' , 'application/json' ) ; } else { $ response = $ view -> render ( $ response , 'error' , $ errorInfo ) ; } $ this -> emitResponse ( $ response ) ; return \ Whoops \ Handler \ Handler :: DONE ; } ) ) ; } $ whoops -> register ( ) ; }
Registers error handler for this application
Registers error handler for this application