rhgrant10 / berserk

Python client for the lichess API
https://berserk.readthedocs.io
Other
141 stars 36 forks source link

error messages for 400 return codes #6

Closed WolfgangFahl closed 4 years ago

WolfgangFahl commented 4 years ago

Description

According to https://lichess.org/api some calls will return error information with a 404 status code e.g. "Authorization header missing".

What I Did

   def abort(self):
        try:
            self.client.bots.abort_game(self.game_id)
            return True
        except requests.exceptions.HTTPError as httpError:
            return self.handle(httpError)

   def handle(self,httpError):
        if self.debug:
            print (httpError)
        return False

The httpError does not seem to carry any detail information which might be necessary for a proper control flow.

rhgrant10 commented 4 years ago

@WolfgangFahl per your comments on your PR, it was easier to just incorporate your changes. Versions 0.5.0 and later now provide custom exception types for response errors that exposes the HTTP code, reason, and also the cause of the error as reported by the API as attributes and in the exception message.