onServerResponse method
Processes server responses
Implementation
void onServerResponse(List<String> responseTexts) {
if (isLogEnabled) {
for (final responseText in responseTexts) {
log(responseText, isClient: false);
}
}
final command = _currentCommand;
if (command == null) {
logApp(
'ignoring response starting with '
'[${responseTexts.isEmpty ? '' : responseTexts.first}] '
'with ${responseTexts.length} lines.',
);
return;
}
try {
final parser = command.parser ?? _standardParser;
final response = parser.parse(responseTexts);
final commandText = command.nextCommand(response);
if (commandText != null) {
// the reply to the follow-up has to be read afresh, otherwise the
// current first line would be dispatched again
_currentFirstResponseLine = null;
_write(() => writeText(commandText), command);
} else if (command.isCommandDone(response)) {
if (response.isFailedStatus) {
command.completer.completeError(PopException(this, response));
} else {
command.completer.complete(response.result);
}
_currentCommand = null;
}
} catch (e, s) {
// a malformed server reply must fail the command, not leave it pending
logApp('Unable to process response: $e $s');
_failCurrentCommand('unable to process response: $e', s);
}
}