apple_music
apple_music copied to clipboard
Handle re-intializing a new client when the auth token expires
Problem:
I was seeing that after having my server running a while, search results for songs that had been returning results were suddenly an empty array. Inspecting the API's results before the gem returned them showed a 401
error.
Looking at the gem's connection.rb
, the client is being memoized with the config.authentication_token
which expires after a day.
One suggestion is to improve the handling of API responses to alert when the request is no longer authenticated. This would have helped me see the real problem immediately.
Another suggestion is to check if the token is expired and initialize a new client with a fresh token.