facebook / facebook-ruby-business-sdk

Ruby SDK for Meta Marketing API
https://developers.facebook.com/docs/business-sdk
Other
208 stars 161 forks source link

How can i get Facebook error codes from a "FacebookAds::ClientError" #64

Closed iamricks closed 5 years ago

iamricks commented 5 years ago

What's the issue?

When handling errors with Facebook, best practice is to use the error codes since the descriptions can change.

Facebook lays out the error codes here to make it easier to handle: https://developers.facebook.com/docs/marketing-api/error-reference/

Observed Results:

It looks like the only things being returned are fb_message, error_user_title and fbtrace_id according to this: https://github.com/facebook/facebook-ruby-business-sdk/blob/55700ad0afee5fa4a8f521ad4615fcff54d2d6a9/lib/facebook_ads/errors.rb

Expected Results:

It should return an error code for the message being returned

Question:

Is there any way to get this error code that belongs to the message?

iamricks commented 5 years ago

I didn't review the code thoroughly enough.

Looks like you can just do e.code on the error and receive the code for the exception that is raised.