{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE StrictData #-}
module Captcha.CapMonster.Internal.Error where
import Control.Exception (Exception)
import Data.Foldable (find)
import Data.Text (Text)
import Network.HTTP.Client (HttpException)
data CapMonsterError
=
CapMonsterResponseError CapMonsterErrorCode
|
UnknownResponseError Text Text
|
UnknownError Text
|
NetworkError HttpException
|
TimeoutError
deriving (Int -> CapMonsterError -> ShowS
[CapMonsterError] -> ShowS
CapMonsterError -> String
(Int -> CapMonsterError -> ShowS)
-> (CapMonsterError -> String)
-> ([CapMonsterError] -> ShowS)
-> Show CapMonsterError
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CapMonsterError] -> ShowS
$cshowList :: [CapMonsterError] -> ShowS
show :: CapMonsterError -> String
$cshow :: CapMonsterError -> String
showsPrec :: Int -> CapMonsterError -> ShowS
$cshowsPrec :: Int -> CapMonsterError -> ShowS
Show, Show CapMonsterError
Typeable CapMonsterError
Typeable CapMonsterError
-> Show CapMonsterError
-> (CapMonsterError -> SomeException)
-> (SomeException -> Maybe CapMonsterError)
-> (CapMonsterError -> String)
-> Exception CapMonsterError
SomeException -> Maybe CapMonsterError
CapMonsterError -> String
CapMonsterError -> SomeException
forall e.
Typeable e
-> Show e
-> (e -> SomeException)
-> (SomeException -> Maybe e)
-> (e -> String)
-> Exception e
displayException :: CapMonsterError -> String
$cdisplayException :: CapMonsterError -> String
fromException :: SomeException -> Maybe CapMonsterError
$cfromException :: SomeException -> Maybe CapMonsterError
toException :: CapMonsterError -> SomeException
$ctoException :: CapMonsterError -> SomeException
$cp2Exception :: Show CapMonsterError
$cp1Exception :: Typeable CapMonsterError
Exception)
data CapMonsterErrorCode
=
KeyDoesNotExist
|
ZeroCaptchaFileSize
|
TooBigFileSize
|
ZeroBalance
|
IpNotAllowed
|
CaptchaUnsolvable
|
InvalidCaptchaId
|
CaptchaNotReady
|
IpBanned
|
NoSuchMethod
|
TooManyRequests
|
DomainNotAllowed
|
NoSlotAvailable
deriving (Int -> CapMonsterErrorCode -> ShowS
[CapMonsterErrorCode] -> ShowS
CapMonsterErrorCode -> String
(Int -> CapMonsterErrorCode -> ShowS)
-> (CapMonsterErrorCode -> String)
-> ([CapMonsterErrorCode] -> ShowS)
-> Show CapMonsterErrorCode
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CapMonsterErrorCode] -> ShowS
$cshowList :: [CapMonsterErrorCode] -> ShowS
show :: CapMonsterErrorCode -> String
$cshow :: CapMonsterErrorCode -> String
showsPrec :: Int -> CapMonsterErrorCode -> ShowS
$cshowsPrec :: Int -> CapMonsterErrorCode -> ShowS
Show, CapMonsterErrorCode -> CapMonsterErrorCode -> Bool
(CapMonsterErrorCode -> CapMonsterErrorCode -> Bool)
-> (CapMonsterErrorCode -> CapMonsterErrorCode -> Bool)
-> Eq CapMonsterErrorCode
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CapMonsterErrorCode -> CapMonsterErrorCode -> Bool
$c/= :: CapMonsterErrorCode -> CapMonsterErrorCode -> Bool
== :: CapMonsterErrorCode -> CapMonsterErrorCode -> Bool
$c== :: CapMonsterErrorCode -> CapMonsterErrorCode -> Bool
Eq, Eq CapMonsterErrorCode
Eq CapMonsterErrorCode
-> (CapMonsterErrorCode -> CapMonsterErrorCode -> Ordering)
-> (CapMonsterErrorCode -> CapMonsterErrorCode -> Bool)
-> (CapMonsterErrorCode -> CapMonsterErrorCode -> Bool)
-> (CapMonsterErrorCode -> CapMonsterErrorCode -> Bool)
-> (CapMonsterErrorCode -> CapMonsterErrorCode -> Bool)
-> (CapMonsterErrorCode
-> CapMonsterErrorCode -> CapMonsterErrorCode)
-> (CapMonsterErrorCode
-> CapMonsterErrorCode -> CapMonsterErrorCode)
-> Ord CapMonsterErrorCode
CapMonsterErrorCode -> CapMonsterErrorCode -> Bool
CapMonsterErrorCode -> CapMonsterErrorCode -> Ordering
CapMonsterErrorCode -> CapMonsterErrorCode -> CapMonsterErrorCode
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: CapMonsterErrorCode -> CapMonsterErrorCode -> CapMonsterErrorCode
$cmin :: CapMonsterErrorCode -> CapMonsterErrorCode -> CapMonsterErrorCode
max :: CapMonsterErrorCode -> CapMonsterErrorCode -> CapMonsterErrorCode
$cmax :: CapMonsterErrorCode -> CapMonsterErrorCode -> CapMonsterErrorCode
>= :: CapMonsterErrorCode -> CapMonsterErrorCode -> Bool
$c>= :: CapMonsterErrorCode -> CapMonsterErrorCode -> Bool
> :: CapMonsterErrorCode -> CapMonsterErrorCode -> Bool
$c> :: CapMonsterErrorCode -> CapMonsterErrorCode -> Bool
<= :: CapMonsterErrorCode -> CapMonsterErrorCode -> Bool
$c<= :: CapMonsterErrorCode -> CapMonsterErrorCode -> Bool
< :: CapMonsterErrorCode -> CapMonsterErrorCode -> Bool
$c< :: CapMonsterErrorCode -> CapMonsterErrorCode -> Bool
compare :: CapMonsterErrorCode -> CapMonsterErrorCode -> Ordering
$ccompare :: CapMonsterErrorCode -> CapMonsterErrorCode -> Ordering
$cp1Ord :: Eq CapMonsterErrorCode
Ord, Int -> CapMonsterErrorCode
CapMonsterErrorCode -> Int
CapMonsterErrorCode -> [CapMonsterErrorCode]
CapMonsterErrorCode -> CapMonsterErrorCode
CapMonsterErrorCode -> CapMonsterErrorCode -> [CapMonsterErrorCode]
CapMonsterErrorCode
-> CapMonsterErrorCode
-> CapMonsterErrorCode
-> [CapMonsterErrorCode]
(CapMonsterErrorCode -> CapMonsterErrorCode)
-> (CapMonsterErrorCode -> CapMonsterErrorCode)
-> (Int -> CapMonsterErrorCode)
-> (CapMonsterErrorCode -> Int)
-> (CapMonsterErrorCode -> [CapMonsterErrorCode])
-> (CapMonsterErrorCode
-> CapMonsterErrorCode -> [CapMonsterErrorCode])
-> (CapMonsterErrorCode
-> CapMonsterErrorCode -> [CapMonsterErrorCode])
-> (CapMonsterErrorCode
-> CapMonsterErrorCode
-> CapMonsterErrorCode
-> [CapMonsterErrorCode])
-> Enum CapMonsterErrorCode
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: CapMonsterErrorCode
-> CapMonsterErrorCode
-> CapMonsterErrorCode
-> [CapMonsterErrorCode]
$cenumFromThenTo :: CapMonsterErrorCode
-> CapMonsterErrorCode
-> CapMonsterErrorCode
-> [CapMonsterErrorCode]
enumFromTo :: CapMonsterErrorCode -> CapMonsterErrorCode -> [CapMonsterErrorCode]
$cenumFromTo :: CapMonsterErrorCode -> CapMonsterErrorCode -> [CapMonsterErrorCode]
enumFromThen :: CapMonsterErrorCode -> CapMonsterErrorCode -> [CapMonsterErrorCode]
$cenumFromThen :: CapMonsterErrorCode -> CapMonsterErrorCode -> [CapMonsterErrorCode]
enumFrom :: CapMonsterErrorCode -> [CapMonsterErrorCode]
$cenumFrom :: CapMonsterErrorCode -> [CapMonsterErrorCode]
fromEnum :: CapMonsterErrorCode -> Int
$cfromEnum :: CapMonsterErrorCode -> Int
toEnum :: Int -> CapMonsterErrorCode
$ctoEnum :: Int -> CapMonsterErrorCode
pred :: CapMonsterErrorCode -> CapMonsterErrorCode
$cpred :: CapMonsterErrorCode -> CapMonsterErrorCode
succ :: CapMonsterErrorCode -> CapMonsterErrorCode
$csucc :: CapMonsterErrorCode -> CapMonsterErrorCode
Enum, CapMonsterErrorCode
CapMonsterErrorCode
-> CapMonsterErrorCode -> Bounded CapMonsterErrorCode
forall a. a -> a -> Bounded a
maxBound :: CapMonsterErrorCode
$cmaxBound :: CapMonsterErrorCode
minBound :: CapMonsterErrorCode
$cminBound :: CapMonsterErrorCode
Bounded)
errorCode :: CapMonsterErrorCode -> Text
errorCode :: CapMonsterErrorCode -> Text
errorCode = \case
CapMonsterErrorCode
KeyDoesNotExist -> Text
"ERROR_KEY_DOES_NOT_EXIST"
CapMonsterErrorCode
ZeroCaptchaFileSize -> Text
"ERROR_ZERO_CAPTCHA_FILESIZE"
CapMonsterErrorCode
TooBigFileSize -> Text
"ERROR_TOO_BIG_CAPTCHA_FILESIZE"
CapMonsterErrorCode
ZeroBalance -> Text
"ERROR_ZERO_BALANCE"
CapMonsterErrorCode
IpNotAllowed -> Text
"ERROR_IP_NOT_ALLOWED"
CapMonsterErrorCode
CaptchaUnsolvable -> Text
"ERROR_CAPTCHA_UNSOLVABLE"
CapMonsterErrorCode
InvalidCaptchaId -> Text
"ERROR_NO_SUCH_CAPCHA_ID"
CapMonsterErrorCode
CaptchaNotReady -> Text
"CAPTCHA_NOT_READY"
CapMonsterErrorCode
IpBanned -> Text
"ERROR_IP_BANNED"
CapMonsterErrorCode
NoSuchMethod -> Text
"ERROR_NO_SUCH_METHOD"
CapMonsterErrorCode
TooManyRequests -> Text
"ERROR_TOO_MUCH_REQUESTS"
CapMonsterErrorCode
DomainNotAllowed -> Text
"ERROR_DOMAIN_NOT_ALLOWED"
CapMonsterErrorCode
NoSlotAvailable -> Text
"ERROR_NO_SLOT_AVAILABLE"
parseError :: Text -> Maybe CapMonsterErrorCode
parseError :: Text -> Maybe CapMonsterErrorCode
parseError Text
code = (CapMonsterErrorCode -> Bool)
-> [CapMonsterErrorCode] -> Maybe CapMonsterErrorCode
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Maybe a
find ((Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text
code) (Text -> Bool)
-> (CapMonsterErrorCode -> Text) -> CapMonsterErrorCode -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CapMonsterErrorCode -> Text
errorCode) [CapMonsterErrorCode
forall a. Bounded a => a
minBound .. CapMonsterErrorCode
forall a. Bounded a => a
maxBound]