TheRealAgentK/facebook-cf-sdk

FacebookBase.cfc error catching

Closed this issue · 3 comments

To repeat error:

  1. Install sample app example.
  2. Login
  3. In new window, log out of Facebook.
  4. Reload App page.
    a) Code was invalid or expired error occurs, but then error is thrown via the throw tag.

Possible fix:
Move throw tag from line 75 up to a cfelse around line 73.

  1. } else {
  2.                     throw(errorCode="#exception.getErrorCode()#", message="#exception.getType()# - #exception.getMessage()#", type="#exception.getType()#");
    
  3.                 }
    

This is an expected behavior.
As a best practice, you should always surround your Facebook api calls inside try/catch and handle errors that might occurs.

If we do not throw an error, you would get an empty result and you would not understand why.

I agree that if you get an unknown error, it needs to be thrown, but the error received is expected (Code was invalid or expired) and caught by line 70. If it is an expected error, and caught so that the invalidateUser routine is run, then I would think that there would be no need to throw the error to the user. that is why I moved the throw statement up into and else statement, so it is only run if an error is received that is unexpected. With that change, everything appears to be running as intended.

In your case, it might be correct but the FacebookBase.cfc is used for all Graph API calls.
In more complex use cases, you need to know if something went wrong during the API call.

For example, if you use permanent auth token stored in a db, you need to catch this type of error to invalidate the token in your DB (and send an email to the user asking him to reconnect to update the token).