ShokoAnime / ShokoServer

Repository for Shoko Server.
http://shokoanime.com/shoko-server/
MIT License
376 stars 74 forks source link

Handle "HTTP 400 and 410" for Trakt Auth correctly... #1064

Closed krbrs closed 1 year ago

krbrs commented 1 year ago

...to actually show a correct message instead of throwing an exception.

According to the API, it means: "400 Pending - waiting for the user to authorize your app" So error 400 keeps showing until Trakt is correctly authorized/linked and approved using the displayed code.

Created a new helper SendDataAuth which handles HTTP 400 differently from other SendData and also made changes to show the correct messages in Shoko logs.

closes #1062

revam commented 1 year ago

Isn't there a string to grep for in the response body to indicate that the 400 is because the app authentication is still pending?

Asking since a 400 response code in HTTP is used for any generic errors, and it would be bad for Trakt to reserve the code exclusively for pending auth. errors.

krbrs commented 1 year ago

For the auth workflow 400 is "pending" - hence the introduction of a new SendDataAuth function:

https://trakt.docs.apiary.io/#reference/authentication-devices/device-code

400 - Pending - waiting for the user to authorize your app

For other requests 400 will be handled as before, because:

https://trakt.docs.apiary.io/#introduction/status-codes

400 - Bad Request - request couldn't be parsed

Blame Trakt for using 400 for this 🙄