/** * React to any console exceptions. * * @param ConsoleExceptionEvent $event */ 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() . " \nRequest URL: " . $request->getUrl() . " \nPlease check your Internet connection")); $event->stopPropagation(); } // Handle Guzzle client exceptions, i.e. HTTP 4xx errors. if ($exception instanceof ClientException && ($response = $exception->getResponse())) { $request = $exception->getRequest(); try { $response->getBody()->seek(0); $json = $response->json(); } catch (ParseException $e) { $json = []; } // 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: please log in again." . " \nRequest URL: " . $request->getUrl())); $event->stopPropagation(); } elseif ($response->getStatusCode() === 401) { $event->setException(new LoginRequiredException("Unauthorized: please log in again." . " \nRequest URL: " . $request->getUrl())); $event->stopPropagation(); } } }
/** * React to any console exceptions. * * @param ConsoleExceptionEvent $event */ 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 client exceptions, i.e. HTTP 4xx errors. if ($exception instanceof ClientException && ($response = $exception->getResponse())) { $request = $exception->getRequest(); try { $response->getBody()->seek(0); $json = $response->json(); } catch (ParseException $e) { $json = []; } // 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: please log in again.", $request)); $event->stopPropagation(); } elseif ($response->getStatusCode() === 401) { $event->setException(new LoginRequiredException("Unauthorized: please log in again.", $request)); $event->stopPropagation(); } elseif ($response->getStatusCode() === 403) { $event->setException(new PermissionDeniedException("Permission denied. Check your project or environment permissions.", $request)); $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) { $command = $event->getCommand(); if ($command instanceof PlatformCommand) { $command->clearEnvironmentsCache(); } } }
/** * React to any console exceptions. * * @param ConsoleExceptionEvent $event */ 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(); $response->getBody()->seek(0); $json = (array) json_decode($response->getBody()->getContents(), true); // Create a friendlier message for the OAuth2 "Invalid refresh token" // error. $loginCommand = sprintf('%s login', $this->config->get('application.executable')); if ($response->getStatusCode() === 400 && isset($json['error_description']) && $json['error_description'] === 'Invalid refresh token') { $event->setException(new LoginRequiredException("Invalid refresh token. \nPlease log in again by running: {$loginCommand}", $request, $response)); $event->stopPropagation(); } elseif ($response->getStatusCode() === 401) { $event->setException(new LoginRequiredException("Unauthorized. \nPlease log in again by running: {$loginCommand}", $request, $response)); $event->stopPropagation(); } elseif ($response->getStatusCode() === 403) { $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) { $api = new Api(); $api->clearEnvironmentsCache($exception->getEnvironment()->project); } }
/** * This listener is run when the ConsoleEvents::EXCEPTION event is triggered. * It translate the exception message. If din debug mode the original exception is embedded. * * @param ConsoleExceptionEvent $event */ public function on_exception(ConsoleExceptionEvent $event) { $original_exception = $event->getException(); if ($original_exception instanceof exception_interface) { $parameters = array_merge(array($original_exception->getMessage()), $original_exception->get_parameters()); $message = call_user_func_array(array($this->language, 'lang'), $parameters); if ($this->debug) { $exception = new \RuntimeException($message, $original_exception->getCode(), $original_exception); } else { $exception = new \RuntimeException($message, $original_exception->getCode()); } $event->setException($exception); } }