public function onException(ConsoleExceptionEvent $event)
    {
        $exception = $event->getException();

        // Replace Guzzle connect exceptions with a friendlier message. This
        // also prevents the user from seeing two exceptions (one direct from
        // Guzzle, one from RingPHP).
        if ($exception instanceof ConnectException && strpos($exception->getMessage(), 'cURL error 6') !== false) {
            $request = $exception->getRequest();
            $event->setException(new ConnectionFailedException(
                "Failed to connect to host: " . $request->getHost()
                . " \nPlease check your Internet connection.",
                $request
            ));
            $event->stopPropagation();
        }

        // Handle Guzzle exceptions, i.e. HTTP 4xx or 5xx errors.
        if (($exception instanceof ClientException || $exception instanceof ServerException)
            && ($response = $exception->getResponse())) {
            $request = $exception->getRequest();
            $requestConfig = $request->getConfig();
            $response->getBody()->seek(0);
            $json = (array) json_decode($response->getBody()->getContents(), true);

            // Create a friendlier message for the OAuth2 "Invalid refresh token"
            // error.
            if ($response->getStatusCode() === 400
                && isset($json['error_description'])
                && $json['error_description'] === 'Invalid refresh token') {
                $event->setException(new LoginRequiredException(
                    'Invalid refresh token.',
                    $request,
                    $response,
                    $this->config
                ));
                $event->stopPropagation();
            } elseif ($response->getStatusCode() === 401 && $requestConfig['auth'] === 'oauth2') {
                $event->setException(new LoginRequiredException(
                    'Unauthorized.',
                    $request,
                    $response,
                    $this->config
                ));
                $event->stopPropagation();
            } elseif ($response->getStatusCode() === 403 && $requestConfig['auth'] === 'oauth2') {
                $event->setException(new PermissionDeniedException(
                    "Permission denied. Check your project or environment permissions.",
                    $request,
                    $response
                ));
                $event->stopPropagation();
            } else {
                $event->setException(new HttpException(null, $request, $response));
                $event->stopPropagation();
            }
        }

        // When an environment is found to be in the wrong state, perhaps our
        // cache is old - we should invalidate it.
        if ($exception instanceof EnvironmentStateException) {
            (new Api())->clearEnvironmentsCache($exception->getEnvironment()->project);
        }
    }
public function onException(ConsoleExceptionEvent $event)
    {
        $exception = $event->getException();

        // Replace Guzzle connect exceptions with a friendlier message. This
        // also prevents the user from seeing two exceptions (one direct from
        // Guzzle, one from RingPHP).
        if ($exception instanceof ConnectException && strpos($exception->getMessage(), 'cURL error 6') !== false) {
            $request = $exception->getRequest();
            $event->setException(new ConnectionFailedException(
                "Failed to connect to host: " . $request->getHost()
                . " \nPlease check your Internet connection.",
                $request
            ));
            $event->stopPropagation();
        }

        // Handle Guzzle exceptions, i.e. HTTP 4xx or 5xx errors.
        if (($exception instanceof ClientException || $exception instanceof ServerException)
            && ($response = $exception->getResponse())) {
            $request = $exception->getRequest();
            $requestConfig = $request->getConfig();
            $response->getBody()->seek(0);
            $json = (array) json_decode($response->getBody()->getContents(), true);

            // Create a friendlier message for the OAuth2 "Invalid refresh token"
            // error.
            if ($response->getStatusCode() === 400
                && isset($json['error_description'])
                && $json['error_description'] === 'Invalid refresh token') {
                $event->setException(new LoginRequiredException(
                    'Invalid refresh token.',
                    $request,
                    $response,
                    $this->config
                ));
                $event->stopPropagation();
            } elseif ($response->getStatusCode() === 401 && $requestConfig['auth'] === 'oauth2') {
                $event->setException(new LoginRequiredException(
                    'Unauthorized.',
                    $request,
                    $response,
                    $this->config
                ));
                $event->stopPropagation();
            } elseif ($response->getStatusCode() === 403 && $requestConfig['auth'] === 'oauth2') {
                $event->setException(new PermissionDeniedException(
                    "Permission denied. Check your project or environment permissions.",
                    $request,
                    $response
                ));
                $event->stopPropagation();
            } else {
                $event->setException(new HttpException(null, $request, $response));
                $event->stopPropagation();
            }
        }

        // When an environment is found to be in the wrong state, perhaps our
        // cache is old - we should invalidate it.
        if ($exception instanceof EnvironmentStateException) {
            (new Api())->clearEnvironmentsCache($exception->getEnvironment()->project);
        }
    }
public function onException ( ConsoleExceptionEvent $ event ) { $ exception = $ event -> getException ( ) ; // Replace Guzzle connect exceptions with a friendlier message. This // also prevents the user from seeing two exceptions (one direct from // Guzzle, one from RingPHP). if ( $ exception instanceof ConnectException && strpos ( $ exception -> getMessage ( ) , 'cURL error 6' ) !== false ) { $ request = $ exception -> getRequest ( ) ; $ event -> setException ( new ConnectionFailedException ( "Failed to connect to host: " . $ request -> getHost ( ) . " \nPlease check your Internet connection." , $ request ) ) ; $ event -> stopPropagation ( ) ; } // Handle Guzzle exceptions, i.e. HTTP 4xx or 5xx errors. if ( ( $ exception instanceof ClientException || $ exception instanceof ServerException ) && ( $ response = $ exception -> getResponse ( ) ) ) { $ request = $ exception -> getRequest ( ) ; $ requestConfig = $ request -> getConfig ( ) ; $ response -> getBody ( ) -> seek ( 0 ) ; $ json = ( array ) json_decode ( $ response -> getBody ( ) -> getContents ( ) , true ) ; // Create a friendlier message for the OAuth2 "Invalid refresh token" // error. if ( $ response -> getStatusCode ( ) === 400 && isset ( $ json [ 'error_description' ] ) && $ json [ 'error_description' ] === 'Invalid refresh token' ) { $ event -> setException ( new LoginRequiredException ( 'Invalid refresh token.' , $ request , $ response , $ this -> config ) ) ; $ event -> stopPropagation ( ) ; } elseif ( $ response -> getStatusCode ( ) === 401 && $ requestConfig [ 'auth' ] === 'oauth2' ) { $ event -> setException ( new LoginRequiredException ( 'Unauthorized.' , $ request , $ response , $ this -> config ) ) ; $ event -> stopPropagation ( ) ; } elseif ( $ response -> getStatusCode ( ) === 403 && $ requestConfig [ 'auth' ] === 'oauth2' ) { $ event -> setException ( new PermissionDeniedException ( "Permission denied. Check your project or environment permissions." , $ request , $ response ) ) ; $ event -> stopPropagation ( ) ; } else { $ event -> setException ( new HttpException ( null , $ request , $ response ) ) ; $ event -> stopPropagation ( ) ; } } // When an environment is found to be in the wrong state, perhaps our // cache is old - we should invalidate it. if ( $ exception instanceof EnvironmentStateException ) { ( new Api ( ) ) -> clearEnvironmentsCache ( $ exception -> getEnvironment ( ) -> project ) ; } }
React to any console exceptions.

@param ConsoleExceptionEvent    $event
React to any console exceptions .