{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE StrictData #-}
module Captcha.TwoCaptcha.Internal.Error where
import Control.Exception (Exception)
import Data.Foldable (find)
import Data.Text (Text)
import Network.HTTP.Client (HttpException)
data TwoCaptchaError
= TwoCaptchaResponseError TwoCaptchaErrorCode
| UnknownResponseError Text Text
| UnknownError Text
| NetworkError HttpException
| TimeoutError
deriving (Int -> TwoCaptchaError -> ShowS
[TwoCaptchaError] -> ShowS
TwoCaptchaError -> String
(Int -> TwoCaptchaError -> ShowS)
-> (TwoCaptchaError -> String)
-> ([TwoCaptchaError] -> ShowS)
-> Show TwoCaptchaError
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TwoCaptchaError] -> ShowS
$cshowList :: [TwoCaptchaError] -> ShowS
show :: TwoCaptchaError -> String
$cshow :: TwoCaptchaError -> String
showsPrec :: Int -> TwoCaptchaError -> ShowS
$cshowsPrec :: Int -> TwoCaptchaError -> ShowS
Show, Show TwoCaptchaError
Typeable TwoCaptchaError
Typeable TwoCaptchaError
-> Show TwoCaptchaError
-> (TwoCaptchaError -> SomeException)
-> (SomeException -> Maybe TwoCaptchaError)
-> (TwoCaptchaError -> String)
-> Exception TwoCaptchaError
SomeException -> Maybe TwoCaptchaError
TwoCaptchaError -> String
TwoCaptchaError -> SomeException
forall e.
Typeable e
-> Show e
-> (e -> SomeException)
-> (SomeException -> Maybe e)
-> (e -> String)
-> Exception e
displayException :: TwoCaptchaError -> String
$cdisplayException :: TwoCaptchaError -> String
fromException :: SomeException -> Maybe TwoCaptchaError
$cfromException :: SomeException -> Maybe TwoCaptchaError
toException :: TwoCaptchaError -> SomeException
$ctoException :: TwoCaptchaError -> SomeException
$cp2Exception :: Show TwoCaptchaError
$cp1Exception :: Typeable TwoCaptchaError
Exception)
data TwoCaptchaErrorCode
=
WrongUserKey
|
KeyDoesNotExist
|
ZeroBalance
|
PageUrlMissing
|
NoSlotAvailable
|
ZeroCaptchaFileSize
|
TooBigCaptchaFileSize
|
WrongFileExtension
|
ImageTypeNotSupported
|
UploadFailure
|
IpNotAllowed
|
IpBanned
|
BadTokenOrPageUrl
|
GoogleKeyInvalid
|
GoogleKeyMissing
|
CaptchaImageBlocked
|
TooManyBadImages
|
RateLimited
|
BadParameters
|
BadProxy
|
CaptchaNotReady
|
CaptchaUnsolvable
|
WrongIdFormat
|
WrongCaptchaId
|
BadDuplicates
|
ReportNotRecorded
|
DuplicateReport
|
TokenExpired
|
EmptyAction
|
ProxyConnectionFailed
deriving (Int -> TwoCaptchaErrorCode -> ShowS
[TwoCaptchaErrorCode] -> ShowS
TwoCaptchaErrorCode -> String
(Int -> TwoCaptchaErrorCode -> ShowS)
-> (TwoCaptchaErrorCode -> String)
-> ([TwoCaptchaErrorCode] -> ShowS)
-> Show TwoCaptchaErrorCode
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TwoCaptchaErrorCode] -> ShowS
$cshowList :: [TwoCaptchaErrorCode] -> ShowS
show :: TwoCaptchaErrorCode -> String
$cshow :: TwoCaptchaErrorCode -> String
showsPrec :: Int -> TwoCaptchaErrorCode -> ShowS
$cshowsPrec :: Int -> TwoCaptchaErrorCode -> ShowS
Show, TwoCaptchaErrorCode -> TwoCaptchaErrorCode -> Bool
(TwoCaptchaErrorCode -> TwoCaptchaErrorCode -> Bool)
-> (TwoCaptchaErrorCode -> TwoCaptchaErrorCode -> Bool)
-> Eq TwoCaptchaErrorCode
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TwoCaptchaErrorCode -> TwoCaptchaErrorCode -> Bool
$c/= :: TwoCaptchaErrorCode -> TwoCaptchaErrorCode -> Bool
== :: TwoCaptchaErrorCode -> TwoCaptchaErrorCode -> Bool
$c== :: TwoCaptchaErrorCode -> TwoCaptchaErrorCode -> Bool
Eq, Eq TwoCaptchaErrorCode
Eq TwoCaptchaErrorCode
-> (TwoCaptchaErrorCode -> TwoCaptchaErrorCode -> Ordering)
-> (TwoCaptchaErrorCode -> TwoCaptchaErrorCode -> Bool)
-> (TwoCaptchaErrorCode -> TwoCaptchaErrorCode -> Bool)
-> (TwoCaptchaErrorCode -> TwoCaptchaErrorCode -> Bool)
-> (TwoCaptchaErrorCode -> TwoCaptchaErrorCode -> Bool)
-> (TwoCaptchaErrorCode
-> TwoCaptchaErrorCode -> TwoCaptchaErrorCode)
-> (TwoCaptchaErrorCode
-> TwoCaptchaErrorCode -> TwoCaptchaErrorCode)
-> Ord TwoCaptchaErrorCode
TwoCaptchaErrorCode -> TwoCaptchaErrorCode -> Bool
TwoCaptchaErrorCode -> TwoCaptchaErrorCode -> Ordering
TwoCaptchaErrorCode -> TwoCaptchaErrorCode -> TwoCaptchaErrorCode
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 :: TwoCaptchaErrorCode -> TwoCaptchaErrorCode -> TwoCaptchaErrorCode
$cmin :: TwoCaptchaErrorCode -> TwoCaptchaErrorCode -> TwoCaptchaErrorCode
max :: TwoCaptchaErrorCode -> TwoCaptchaErrorCode -> TwoCaptchaErrorCode
$cmax :: TwoCaptchaErrorCode -> TwoCaptchaErrorCode -> TwoCaptchaErrorCode
>= :: TwoCaptchaErrorCode -> TwoCaptchaErrorCode -> Bool
$c>= :: TwoCaptchaErrorCode -> TwoCaptchaErrorCode -> Bool
> :: TwoCaptchaErrorCode -> TwoCaptchaErrorCode -> Bool
$c> :: TwoCaptchaErrorCode -> TwoCaptchaErrorCode -> Bool
<= :: TwoCaptchaErrorCode -> TwoCaptchaErrorCode -> Bool
$c<= :: TwoCaptchaErrorCode -> TwoCaptchaErrorCode -> Bool
< :: TwoCaptchaErrorCode -> TwoCaptchaErrorCode -> Bool
$c< :: TwoCaptchaErrorCode -> TwoCaptchaErrorCode -> Bool
compare :: TwoCaptchaErrorCode -> TwoCaptchaErrorCode -> Ordering
$ccompare :: TwoCaptchaErrorCode -> TwoCaptchaErrorCode -> Ordering
$cp1Ord :: Eq TwoCaptchaErrorCode
Ord, Int -> TwoCaptchaErrorCode
TwoCaptchaErrorCode -> Int
TwoCaptchaErrorCode -> [TwoCaptchaErrorCode]
TwoCaptchaErrorCode -> TwoCaptchaErrorCode
TwoCaptchaErrorCode -> TwoCaptchaErrorCode -> [TwoCaptchaErrorCode]
TwoCaptchaErrorCode
-> TwoCaptchaErrorCode
-> TwoCaptchaErrorCode
-> [TwoCaptchaErrorCode]
(TwoCaptchaErrorCode -> TwoCaptchaErrorCode)
-> (TwoCaptchaErrorCode -> TwoCaptchaErrorCode)
-> (Int -> TwoCaptchaErrorCode)
-> (TwoCaptchaErrorCode -> Int)
-> (TwoCaptchaErrorCode -> [TwoCaptchaErrorCode])
-> (TwoCaptchaErrorCode
-> TwoCaptchaErrorCode -> [TwoCaptchaErrorCode])
-> (TwoCaptchaErrorCode
-> TwoCaptchaErrorCode -> [TwoCaptchaErrorCode])
-> (TwoCaptchaErrorCode
-> TwoCaptchaErrorCode
-> TwoCaptchaErrorCode
-> [TwoCaptchaErrorCode])
-> Enum TwoCaptchaErrorCode
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 :: TwoCaptchaErrorCode
-> TwoCaptchaErrorCode
-> TwoCaptchaErrorCode
-> [TwoCaptchaErrorCode]
$cenumFromThenTo :: TwoCaptchaErrorCode
-> TwoCaptchaErrorCode
-> TwoCaptchaErrorCode
-> [TwoCaptchaErrorCode]
enumFromTo :: TwoCaptchaErrorCode -> TwoCaptchaErrorCode -> [TwoCaptchaErrorCode]
$cenumFromTo :: TwoCaptchaErrorCode -> TwoCaptchaErrorCode -> [TwoCaptchaErrorCode]
enumFromThen :: TwoCaptchaErrorCode -> TwoCaptchaErrorCode -> [TwoCaptchaErrorCode]
$cenumFromThen :: TwoCaptchaErrorCode -> TwoCaptchaErrorCode -> [TwoCaptchaErrorCode]
enumFrom :: TwoCaptchaErrorCode -> [TwoCaptchaErrorCode]
$cenumFrom :: TwoCaptchaErrorCode -> [TwoCaptchaErrorCode]
fromEnum :: TwoCaptchaErrorCode -> Int
$cfromEnum :: TwoCaptchaErrorCode -> Int
toEnum :: Int -> TwoCaptchaErrorCode
$ctoEnum :: Int -> TwoCaptchaErrorCode
pred :: TwoCaptchaErrorCode -> TwoCaptchaErrorCode
$cpred :: TwoCaptchaErrorCode -> TwoCaptchaErrorCode
succ :: TwoCaptchaErrorCode -> TwoCaptchaErrorCode
$csucc :: TwoCaptchaErrorCode -> TwoCaptchaErrorCode
Enum, TwoCaptchaErrorCode
TwoCaptchaErrorCode
-> TwoCaptchaErrorCode -> Bounded TwoCaptchaErrorCode
forall a. a -> a -> Bounded a
maxBound :: TwoCaptchaErrorCode
$cmaxBound :: TwoCaptchaErrorCode
minBound :: TwoCaptchaErrorCode
$cminBound :: TwoCaptchaErrorCode
Bounded)
errorCode :: TwoCaptchaErrorCode -> Text
errorCode :: TwoCaptchaErrorCode -> Text
errorCode = \case
TwoCaptchaErrorCode
WrongUserKey -> Text
"ERROR_WRONG_USER_KEY"
TwoCaptchaErrorCode
KeyDoesNotExist -> Text
"ERROR_KEY_DOES_NOT_EXIST"
TwoCaptchaErrorCode
ZeroBalance -> Text
"ERROR_ZERO_BALANCE"
TwoCaptchaErrorCode
PageUrlMissing -> Text
"ERROR_PAGEURL"
TwoCaptchaErrorCode
NoSlotAvailable -> Text
"ERROR_NO_SLOT_AVAILABLE"
TwoCaptchaErrorCode
ZeroCaptchaFileSize -> Text
"ERROR_ZERO_CAPTCHA_FILESIZE"
TwoCaptchaErrorCode
TooBigCaptchaFileSize -> Text
"ERROR_TOO_BIG_CAPTCHA_FILESIZE"
TwoCaptchaErrorCode
WrongFileExtension -> Text
"ERROR_WRONG_FILE_EXTENSION"
TwoCaptchaErrorCode
ImageTypeNotSupported -> Text
"ERROR_IMAGE_TYPE_NOT_SUPPORTED"
TwoCaptchaErrorCode
UploadFailure -> Text
"ERROR_UPLOAD"
TwoCaptchaErrorCode
IpNotAllowed -> Text
"ERROR_IP_NOT_ALLOWED"
TwoCaptchaErrorCode
IpBanned -> Text
"IP_BANNED"
TwoCaptchaErrorCode
BadTokenOrPageUrl -> Text
"ERROR_BAD_TOKEN_OR_PAGEURL"
TwoCaptchaErrorCode
GoogleKeyInvalid -> Text
"ERROR_GOOGLEKEY"
TwoCaptchaErrorCode
GoogleKeyMissing -> Text
"ERROR_WRONG_GOOGLEKEY"
TwoCaptchaErrorCode
CaptchaImageBlocked -> Text
"ERROR_CAPTCHAIMAGE_BLOCKED"
TwoCaptchaErrorCode
TooManyBadImages -> Text
"TOO_MANY_BAD_IMAGES"
TwoCaptchaErrorCode
RateLimited -> Text
"MAX_USER_TURN"
TwoCaptchaErrorCode
BadParameters -> Text
"ERROR_BAD_PARAMETERS"
TwoCaptchaErrorCode
BadProxy -> Text
"ERROR_BAD_PROXY"
TwoCaptchaErrorCode
CaptchaNotReady -> Text
"CAPCHA_NOT_READY"
TwoCaptchaErrorCode
CaptchaUnsolvable -> Text
"ERROR_CAPTCHA_UNSOLVABLE"
TwoCaptchaErrorCode
WrongIdFormat -> Text
"ERROR_WRONG_ID_FORMAT"
TwoCaptchaErrorCode
WrongCaptchaId -> Text
"ERROR_WRONG_CAPTCHA_ID"
TwoCaptchaErrorCode
BadDuplicates -> Text
"ERROR_BAD_DUPLICATES"
TwoCaptchaErrorCode
ReportNotRecorded -> Text
"ERROR_REPORT_NOT_RECORDED"
TwoCaptchaErrorCode
DuplicateReport -> Text
"ERROR_DUPLICATE_REPORT"
TwoCaptchaErrorCode
TokenExpired -> Text
"ERROR_TOKEN_EXPIRED"
TwoCaptchaErrorCode
EmptyAction -> Text
"ERROR_EMPTY_ACTION"
TwoCaptchaErrorCode
ProxyConnectionFailed -> Text
"ERROR_PROXY_CONNECTION_FAILED"
parseError :: Text -> Maybe TwoCaptchaErrorCode
parseError :: Text -> Maybe TwoCaptchaErrorCode
parseError Text
code = (TwoCaptchaErrorCode -> Bool)
-> [TwoCaptchaErrorCode] -> Maybe TwoCaptchaErrorCode
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)
-> (TwoCaptchaErrorCode -> Text) -> TwoCaptchaErrorCode -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TwoCaptchaErrorCode -> Text
errorCode) [TwoCaptchaErrorCode
forall a. Bounded a => a
minBound .. TwoCaptchaErrorCode
forall a. Bounded a => a
maxBound]