1
0
mirror of https://github.com/moparisthebest/Yaaic synced 2024-11-26 02:42:16 -05:00

Handle exceptions on connect

This commit is contained in:
Sebastian Kaspari 2010-03-14 11:53:54 +01:00
parent 5140646fd4
commit 0a0190c219

View File

@ -20,12 +20,16 @@ along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
*/ */
package org.yaaic.irc; package org.yaaic.irc;
import java.io.IOException;
import org.jibble.pircbot.IrcException; import org.jibble.pircbot.IrcException;
import org.jibble.pircbot.NickAlreadyInUseException; import org.jibble.pircbot.NickAlreadyInUseException;
import org.yaaic.R;
import org.yaaic.model.Broadcast;
import org.yaaic.model.Message;
import org.yaaic.model.Server; import org.yaaic.model.Server;
import org.yaaic.model.ServerInfo;
import org.yaaic.model.Status;
import android.content.Intent;
import android.os.Binder; import android.os.Binder;
import android.util.Log; import android.util.Log;
@ -74,14 +78,34 @@ public class IRCBinder extends Binder
connection.connect(server.getHost(), server.getPort()); connection.connect(server.getHost(), server.getPort());
} }
} }
catch (NickAlreadyInUseException e) { catch (Exception e) {
Log.d(TAG, "NickAlreadyInUseException: " + e.getMessage()); Log.d(TAG, "Exception: " + e.getMessage());
}
catch (IrcException e) {
Log.d(TAG, "IrcException: " + e.getMessage()); server.setStatus(Status.DISCONNECTED);
} Intent sIntent = new Intent(Broadcast.SERVER_UPDATE);
catch (IOException e) { sIntent.putExtra(Broadcast.EXTRA_SERVER, server.getId());
Log.d(TAG, "IOException: " + e.getMessage()); service.sendBroadcast(sIntent);
IRCConnection connection = getService().getConnection(server.getId());
Message message;
if (e instanceof NickAlreadyInUseException) {
message = new Message("Nickname " + connection.getNick() + " already in use");
} else if (e instanceof IrcException) {
message = new Message("Could not log into the IRC server " + server.getHost());
} else {
message = new Message("Could not connect to IRC server " + server.getHost());
}
message.setColor(Message.COLOR_RED);
message.setIcon(R.drawable.error);
Intent cIntent = new Intent(Broadcast.CONVERSATION_MESSAGE);
cIntent.putExtra(Broadcast.EXTRA_SERVER, server.getId());
cIntent.putExtra(Broadcast.EXTRA_CONVERSATION, ServerInfo.DEFAULT_NAME);
service.sendBroadcast(cIntent);
} }
} }
}.start(); }.start();