Added error handling to `listChannels()`

This commit is contained in:
Tristan B. Kildaire 2020-12-20 14:30:42 +02:00
parent 706042198c
commit 6292ba0852
1 changed files with 26 additions and 11 deletions

View File

@ -437,20 +437,35 @@ public final class DClient
/* Send the protocol data */
DataMessage protocolDataMsg = new DataMessage(reqRepQueue.getTag(), data);
bSendMessage(socket, protocolDataMsg.encode());
bool status = bSendMessage(socket, protocolDataMsg.encode());
/* Receive the server's response */
byte[] resp = reqRepQueue.dequeue().getData();
/* Only generate a list if command was successful */
if(resp[0])
/* If the send worked */
if(status)
{
/* Generate the channel list */
string channelList = cast(string)resp[1..resp.length];
channels = split(channelList, ",");
}
return channels;
/* Receive the server's response */
byte[] resp = reqRepQueue.dequeue().getData();
/* Only generate a list if command was successful */
if(resp[0])
{
/* Generate the channel list */
string channelList = cast(string)resp[1..resp.length];
channels = split(channelList, ",");
}
/* If it didn't work */
else
{
throw new DClientException("Channel list error");
}
return channels;
}
/* If the send failed */
else
{
throw new DNetworkError("listchannels");
}
}
public Manager getManager()