Discord: Don't log IOExceptions to error logs, and also better log errors with IRC

This commit is contained in:
UnknownShadow200 2021-06-15 21:33:47 +10:00
parent 5cc8c82936
commit 8960dcd66f
5 changed files with 6 additions and 32 deletions

View File

@ -116,7 +116,7 @@ namespace MCGalaxy.Modules.Relay.Discord {
byte[] data = new byte[4096];
for (;;) {
int len = stream.Read(data, 0, 4096);
if (len == 0) throw new EndOfStreamException("stream.Read returned 0");
if (len == 0) throw new IOException("stream.Read returned 0");
HandleReceived(data, len);
}

View File

@ -156,7 +156,10 @@ namespace MCGalaxy.Modules.Relay {
// SocketException is usually due to complete connection dropout
retries = 0;
Thread.Sleep(30 * 1000);
} catch (Exception ex) {
} catch (IOException ex) {
// IOException is an expected error, so don't log full details
Logger.Log(LogType.Warning, "{0} read error ({1})", RelayName, ex.Message);
} catch (Exception ex) {
Logger.LogError(RelayName + " relay error", ex);
}
retries++;

View File

@ -192,23 +192,13 @@ namespace Sharkbite.Irc
}
}
}
catch (IOException)
{
//Trap a connection failure
listener.Error( ReplyCode.ConnectionFailed, "Connection to server unexpectedly failed.");
}
catch (Exception ex)
{
listener.Error( ReplyCode.ConnectionFailed, "Unhandled error: " + ex);
}
finally
{
//The connection to the IRC server has been closed either
//by client request or the server itself closed the connection.
client.Close();
registered = false;
connected = false;
listener.Disconnected();
connected = false;
}
}
/// <summary>

View File

@ -77,10 +77,6 @@ namespace Sharkbite.Irc
/// </summary>
public event RegisteredEventHandler OnRegistered;
/// <summary>
/// This connection has been closed.
/// </summary>
public event DisconnectedEventHandler OnDisconnected;
/// <summary>
/// A Notice type message was sent to a channel.
/// </summary>
public event PublicNoticeEventHandler OnPublicNotice;
@ -204,16 +200,6 @@ namespace Sharkbite.Irc
}
}
/// <summary>
/// Tell listeners that this connection is closed
/// </summary>
internal void Disconnected()
{
if( OnDisconnected != null )
{
OnDisconnected();
}
}
/// <summary>
/// Tell listeners that an error has been encountered
/// </summary>
internal void Error( ReplyCode code, string message )

View File

@ -118,11 +118,6 @@ namespace Sharkbite.Irc
/// </summary>
ERR_USERSDONTMATCH = 502,
/// <summary>
/// When the TCP/IP connection unexpectedly fails.
/// </summary>
ConnectionFailed = 1000,
/// <summary>
/// The IRC server sent an 'ERROR' message for some
/// reason.