tags:

views:

56

answers:

4

What is the best workflow taken when connection error occurs. Let say we have a client that connects to the middle tier.

class MyClient{   
...   
  void   callServer(){  
    try{  
      middletier.saveRecord(123);  
    }catch(...){  
      // log the error  
      // what to do next (notify the user, take the same step again)?  
      // reinitialize connection ?  
    }  
  }  
}

What to do if the connection error occured (time out, broken connection ...)

Should I notify the user that the connection has a problem and to try again? Can something be done automatically, and transparent for the user ?

All I like is, not to bother the user with errors and then to tell the user what to do next.
So what is the best workflow for handling such errors ?

+2  A: 

This is absolutely dependent on application requirements. Sometimes it is better to inform user immediately and sometimes it is better to retry the request several times before informing the user. You have to consult this with your customer / analyst.

Ladislav Mrnka
My customers do not know this. They are asking me to give the best solution. That is why I am asking about personal best practice.
darko petreski
+1  A: 

From perspective of caller MyClient : Generally speaking, the failed method invocation should leave the MyClient in the state that it was in prior to the invocation. That means you should take care how to recover state of pre-middletier.saveRecord(123);

卢声远 Shengyuan Lu
+3  A: 

I can highly recommend Michael Nygards "Release It!" which spends quite a bit of time explaining how to make your software more robust.

http://www.pragprog.com/titles/mnee/release-it

Thorbjørn Ravn Andersen
+1  A: 

It depends... If the action is caused by user interaction inform the user. The user can decide how often he wants to retry. The code may retry by itself but if it is a timeout than the user may wait for a several minutes (or abort the action not getting any feedback).

If it is a background task, try again after some delay (but not infinitely - eventually abort the action). you may reinitialize the connection to be sure, that depends on the used technology and if you use connection pooling.

Of course if you want to invest more time you can handle different errors differently. First of all, differentiate permanent errors (a retry in a few minutes wouldn't help) from intermittent errors (could be OK the next time). For instance, with a broken connection you could retry with a new one (maybe the firewall dropped an open connection because of inactivity). But you probably can't do anything about a time out (maybe a network configuration problem) or "HTTP 404 Not found" (assuming you can't change the URL you use for a HTTP call).

You could gather all this knowledge in "diagnosis&repair" component.

I also recommend reading "Release it!".

erik