Closed nicolrx closed 7 years ago
Also, is it possible to retrieve the Facebook error to perform an action?
Hi Nicolas!
Did you check if 500 errors on other paths are shown in the logs?
What do you mean by "retrieve the Facebook error to perform an action"?
Hi Ulrich! There is no 500 errors on other paths. Most of the time there is a Facebook error attached but sometimes I just get 500 errors out of the blue on my listening path.
What do I mean by "retrieve the Facebook error to perform an action" is to be able to write an if statement in order to perform some action when a particular error is raised. For example, some of the users remove the permissions but don't desactivate the chatbot. Thus, there are FacebookErrors raised: I would like to be able to desactivate the bot for their page in case they removed the permissions.
Thanks!
There is no 500 errors on other paths. Most of the time there is a Facebook error attached but sometimes I just get 500 errors out of the blue on my listening path.
I would suggest you create a path that would give a 500 error just for testing and see if the error is output in the logs when you visit that path. My guess is there's some config you need to enable for Heroku to log the 500 errors trace. So try a 500 error on another path to confirm. With Rails 4, you had to add the rails_12factor gem to your Gemfile to enable errors logging in Heroku. Not sure if it's still necessary for Rails 5 or if there's something else to do. Haven't used Heroku for a while.
What do I mean by "retrieve the Facebook error to perform an action" is to be able to write an if statement in order to perform some action when a particular error is raised.
You'll need to rescue the exceptions raised (http://blog.honeybadger.io/a-beginner-s-guide-to-exceptions-in-ruby/). There are plenty of error codes that Facebook can return and they're barely documented so you'll need to monitor your logs and rescue them as needed. What we're doing in our app is:
rescue Facebook::Messenger::Bot::AccessTokenError, Facebook::Messenger::FacebookError,
Facebook::Messenger::Bot::PermissionError => e
# code 190: Access Token not valid anymore
# code 230: Requires pages_messaging permission to manage the object
# subcode 460: Error validating access token: The session has been invalidated because
# the user changed their password or Facebook has changed the session for security reasons.
if e.code == 190 || e.code == 230 || e.subcode == 460
# deactivate page and email user
else
raise
end
Hope that helps.
Feel free to reach out anytime (even by email) if there's anything I can help with. I like what you're doing with Botletter!
That's exactly what I needed thanks a lot! I'm not really experienced to rescue exceptions raised, I will probably do a pull request to add this to the documentation.
I really like Botamp's new version too, it seems really promising! Let's stay in touch ;)
Hello Johannes, Sometimes I get 500 errors from Facebook Post requests on my listening route. I don't get any Facebook error printed in my logs so I can't debug it.
Basically it looks like this:
Do you know how I can find the issue for these bad requests?
Thanks.