diff options
author | Julien Dessaux | 2023-07-16 23:31:00 +0200 |
---|---|---|
committer | Julien Dessaux | 2023-07-17 00:15:05 +0200 |
commit | e084d260ff0439f04ab62eba7229309d79ed55c4 (patch) | |
tree | e2355a9dad8123352474cb8533d625f87fdcde0d /haskell/src/SpaceTraders/APIClient/Errors.hs | |
parent | [haskell] Implemented pagination and systems list api call (diff) | |
download | spacetraders-e084d260ff0439f04ab62eba7229309d79ed55c4.tar.gz spacetraders-e084d260ff0439f04ab62eba7229309d79ed55c4.tar.bz2 spacetraders-e084d260ff0439f04ab62eba7229309d79ed55c4.zip |
[haskell] Add a SpaceTradersT and handle server reset api message
Diffstat (limited to '')
-rw-r--r-- | haskell/src/SpaceTraders/APIClient/Errors.hs | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/haskell/src/SpaceTraders/APIClient/Errors.hs b/haskell/src/SpaceTraders/APIClient/Errors.hs index a7f5d21..2b74784 100644 --- a/haskell/src/SpaceTraders/APIClient/Errors.hs +++ b/haskell/src/SpaceTraders/APIClient/Errors.hs @@ -1,17 +1,22 @@ +{-# LANGUAGE DeriveAnyClass #-} +{-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE OverloadedStrings #-} module SpaceTraders.APIClient.Errors ( APIError(..) , RateLimit(..) + , ResetHappened(..) ) where import Control.Exception import Data.Aeson import Data.Time import qualified Data.Text as T +import GHC.Generics data APIError = APIError Int T.Text Value | APIRateLimit RateLimit + | APIResetHappened ResetHappened deriving Show instance Exception APIError instance FromJSON APIError where @@ -20,6 +25,7 @@ instance FromJSON APIError where code <- e .: "code" d <- e .: "data" case code of + 401 -> APIResetHappened <$> parseJSON d 429 -> APIRateLimit <$> parseJSON d _ -> APIError <$> pure code <*> e .: "message" @@ -40,3 +46,7 @@ instance FromJSON RateLimit where <*> o .: "remaining" <*> o .: "reset" <*> o .: "retryAfter" + +data ResetHappened = ResetHappened { actual :: T.Text + , expected :: T.Text + } deriving (FromJSON, Generic, Show, ToJSON) |