improve error handling during connect

This commit is contained in:
Robin Appelman 2018-03-27 17:53:29 +02:00
commit b888dd81bd
2 changed files with 8 additions and 0 deletions

View file

@ -34,10 +34,14 @@ class Connection extends RawConnection {
parent::write($input . PHP_EOL);
}
/**
* @throws ConnectException
*/
public function clearTillPrompt() {
$this->write('');
do {
$promptLine = $this->readLine();
$this->parser->checkConnectionError($promptLine);
} while (!$this->isPrompt($promptLine));
$this->write('');
$this->readLine();

View file

@ -81,6 +81,7 @@ class Parser {
* @throws AuthenticationException
* @throws InvalidHostException
* @throws NoLoginServerException
* @throws AccessDeniedException
*/
public function checkConnectionError($line) {
$line = rtrim($line, ')');
@ -99,6 +100,9 @@ class Parser {
if (substr($line, -26) === ErrorCodes::NoLogonServers) {
throw new NoLoginServerException('No login server');
}
if (substr($line, -23) === ErrorCodes::AccessDenied) {
throw new AccessDeniedException('Access denied');
}
}
public function parseMode($mode) {