Skip to content

Commit

Permalink
improve error handling during connect
Browse files Browse the repository at this point in the history
  • Loading branch information
icewind1991 committed Mar 28, 2018
1 parent 4ad10ae commit b888dd8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,14 @@ public function write($input) {
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();
Expand Down
4 changes: 4 additions & 0 deletions src/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public function checkForError($output, $path) {
* @throws AuthenticationException
* @throws InvalidHostException
* @throws NoLoginServerException
* @throws AccessDeniedException
*/
public function checkConnectionError($line) {
$line = rtrim($line, ')');
Expand All @@ -99,6 +100,9 @@ public function checkConnectionError($line) {
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) {
Expand Down

0 comments on commit b888dd8

Please sign in to comment.