Smack''s error/exception behaviour sucks

Hi,

1.)

Both new XMPPConnection(config) and XMPPConnection.login() can throw an IllegalStateException, e.g. when there is a socket error. IllegalStateException is an unchecked exception, so the method doesn’'t have to declare that it may throw this exception. Nevertheless, I think that the documentation should mention this - or even better, Smack should catch these exceptions and throw more appropriate XMPPExceptions instead.

2.)

When connecting (to wildfire) using a nonexisting login/password, an XMPPException e is thrown with e.getError() == null and e.getMessage() = “SASL authentication failed”. I am annoyed that this error does not return an error code. How am I suppose to tell whether the account doesn’'t exist (and could be created), or another error occurred?

3.)

Why are there no constants for the error codes implemented by XMPPError? Is everyone supposed to hard-code these raw numbers into their application? It would be nice to have constants for these integers. It would also be nice rather than having no message, the constructor XMPPError(int code) constructed an error with the default message for that code.

Cheers,

Tobias

public static String getMessageForCode(int code) {

if (code == 302) return “Redirect”;

if (code == 400) return “Bad Request”;

if (code == 401) return “Not Authorized”;

if (code == 402) return “Payment Required”;

if (code == 403) return “Forbidden”;

if (code == 404) return “Not Found”;

if (code == 405) return “Not Allowed”;

if (code == 406) return “Not Acceptable”;

if (code == 407) return “Registration Required”;

if (code == 408) return “Request Timeout”;

if (code == 409) return “Conflict”;

if (code == 500) return “Internal Server Error”;

if (code == 501) return “Not Implemented”;

if (code == 502) return “Remote Server Error”;

if (code == 503) return “Service Unavailable”;

if (code == 504) return “Remote Server Timeout”;

if (code == 510) return “Disconnected”;

else return null;

}

It’‘s not that I am unable to write such a method myself (except that I would have used a switch statement), but rather I think that such a method should be part of Smack, not of every client that uses Smack. So I’'d appreciate if such a method could be included into smack. Also, I think that it would be nice to publish the names of constants for each error code, rather than the actual number.

hmmm, Smack does provide quite good exception and error handling imo.

How bout something like this

public String getErrorMessage(XMPPException e) {

XMPPError err = e.getXMPPError();

return err.getMessage();

}

/code

How would that help? This only relays method calls and solves neither of 1.-3.). And in 2.), your code would even throw a NullPonterException because e.getXMPPError() returns null.

Can one of the developers make a statement whether any of the above issues 1.-3.) are going to be fixed? I’'m willing to do it myself, if I get accesss to the Smack SVN repository…

Fixing 2.) will probably mean that new XMPPErrors need to be introduced (which is easy if we fix 3.) at the same time).

I wonder why these codes are returned since the rfcs just define the error messages