learn-awesome / learn

A social network of lifelong learners built around humanity's universal learning map.
https://learnawesome.org/
Other
344 stars 40 forks source link

Handle 429 error while fetching opengraph data #173

Closed teampolyglot closed 3 years ago

teampolyglot commented 4 years ago

Got this while adding a youtube video

2020-04-29T17:29:20.447935+00:00 app[web.1]: [86c45999-938d-40b1-89ee-97df9af7f539] OpenURI::HTTPError (429 Too Many Requests):
2020-04-29T17:29:20.447935+00:00 app[web.1]: [86c45999-938d-40b1-89ee-97df9af7f539]
2020-04-29T17:29:20.447936+00:00 app[web.1]: [86c45999-938d-40b1-89ee-97df9af7f539] app/models/item.rb:481:in `block in extract_opengraph_data'
2020-04-29T17:29:20.447936+00:00 app[web.1]: [86c45999-938d-40b1-89ee-97df9af7f539] app/models/item.rb:445:in `extract_opengraph_data'
2020-04-29T17:29:20.447937+00:00 app[web.1]: [86c45999-938d-40b1-89ee-97df9af7f539] app/controllers/items_controller.rb:68:in `create'
2020-04-29T17:29:20.440772+00:00 heroku[router]: at=info method=POST path="/items" host=learnawesome.org request_id=86c45999-938d-40b1-89ee-97df9af7f539 fwd="106.51.29.133,172.68.141.99" dyno=web.1 connect=0ms service=871ms status=500 bytes=2958 protocol=https
jish commented 3 years ago

Hello 👋 I would like to work on this issue.

I see that at the bottom of Item.extract_opengraph_data if an exception is caught, then an error is logged using Rails.logger.error and an empty Hash {} is returned.

https://github.com/learn-awesome/learn/blob/a8234ef43776911ca30d5463af80a1dfee9e86a8/app/models/item.rb#L571-L573

I propose mimicking that behavior for the YouTube specific branch as any callers of Item.extract_opengraph_data could behave the same way.

nileshtrivedi commented 3 years ago

@jish Thanks for the PR. I will have a look at this in a day or two.