Recovering from server error

24 views
Skip to first unread message

mikko.nu...@gmail.com

unread,
Dec 10, 2014, 3:50:09 AM12/10/14
to codenameone...@googlegroups.com
Hello again,

just wondering how can I handle errors like "error 500" while doing a connection request through network manager. I am consuming the error but errors like that are getting through and the application cannot handle that. It is important that when connection is not available application continues with offline mode.

 /**
 * Consumes network error and sets offline mode
 *
 * @param networkManager
 */

 
protected static void consumeNetworkError() {

     
// Consume error and set offline mode on
     
NetworkManager.getInstance().addErrorListener(new ActionListener() {
         
public void actionPerformed(ActionEvent evt) {
                evt
.consume();
               
StateMachine.setOffline(true);
               
RequestInfo.setRequestStatus(RequestStatus.FAILURE);
               
RequestInfo.setMessage("Failed to connect CoMPass server");
               
Dialog.show("Notification:", "Failed to connect CoMPass server, setting offline mode", " OK", null);
           
}
       
});
   
}



Carlos Verdier

unread,
Dec 10, 2014, 4:34:45 AM12/10/14
to codenameone...@googlegroups.com, mikko.nu...@gmail.com
Hi

Have you tried this?

protected void handleErrorResponseCode(int code, String message)

Shai Almog

unread,
Dec 10, 2014, 12:24:42 PM12/10/14
to codenameone...@googlegroups.com, mikko.nu...@gmail.com
Hi,
a 500 error is a response code error and not a networking error. Its usually triggered by a server side error.
You can override the method mentioned by Carlos in the connection request.

mikko.nu...@gmail.com

unread,
Dec 12, 2014, 9:12:26 AM12/12/14
to codenameone...@googlegroups.com, mikko.nu...@gmail.com
Ok,

thanks guys, I'll try this.
Reply all
Reply to author
Forward
0 new messages