This project is read-only.

Handling Errors from Facebook

Nov 11, 2011 at 7:10 PM

Once in a while I'll try to get Posts or do some other operation, and Facebook will timeout or return a server error 500.  So the WebRequest methods throw exceptions.  My application code needs to handle that on every call.  Does anyone have thoughts about pushing some of this handling into the FGT?  On one hand I'd like the toolkit to retry on specific errors.  On the other hand I don't want to force some number of retries for operations where we as developers know that one error is significant.

One could create overloads for various method calls to allow for retries, like IList<foo>=Api.GetFoo(user,token,tries).  But I'm thinking this should be done transparently by having a global setting which is then checked if an error occurs.  For example (I don't have the code in front of me so this is pseudocode...):

string response = GetWebResponse(url, parameters...)


string GetWebResponse(string url, params parameters...) {
  string response = "";
  for (i=1;i<=Common.WebRetries;i++) {
    try {
      // do web request
      break; // successful response, exit loop
    } catch (Exception ex) {
     // execute delegate to report error if any
  return response;

So if there is an error from Facebook the developer can log it or otherwise handle it, but the application code doesn't need to be so concerned with Facebook servers dropping a request here and there.  The Common.Retries static value can be modified prior to calls by the developer, or just left alone to assume a default value of maybe 3 (my preference).

I'll look to see how other libraries handle this.  Any suggestions?