{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE OverloadedStrings #-}
module Network.Mattermost.Exceptions
(
LoginFailureException(..)
, URIParseException(..)
, ContentTypeException(..)
, JSONDecodeException(..)
, HeaderNotFoundException(..)
, HTTPResponseException(..)
, MattermostError(..)
, ConnectionException(..)
, MattermostServerError(..)
, RateLimitException(..)
) where
import qualified Data.Aeson as A
import qualified Data.Text as T
import Data.Typeable ( Typeable )
import Control.Exception ( Exception(..) )
import Network.Stream ( ConnError )
data LoginFailureException = LoginFailureException String
deriving (Int -> LoginFailureException -> ShowS
[LoginFailureException] -> ShowS
LoginFailureException -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [LoginFailureException] -> ShowS
$cshowList :: [LoginFailureException] -> ShowS
show :: LoginFailureException -> String
$cshow :: LoginFailureException -> String
showsPrec :: Int -> LoginFailureException -> ShowS
$cshowsPrec :: Int -> LoginFailureException -> ShowS
Show, Typeable)
instance Exception LoginFailureException
data URIParseException = URIParseException String
deriving (Int -> URIParseException -> ShowS
[URIParseException] -> ShowS
URIParseException -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [URIParseException] -> ShowS
$cshowList :: [URIParseException] -> ShowS
show :: URIParseException -> String
$cshow :: URIParseException -> String
showsPrec :: Int -> URIParseException -> ShowS
$cshowsPrec :: Int -> URIParseException -> ShowS
Show, Typeable)
instance Exception URIParseException
data ContentTypeException = ContentTypeException String
deriving (Int -> ContentTypeException -> ShowS
[ContentTypeException] -> ShowS
ContentTypeException -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ContentTypeException] -> ShowS
$cshowList :: [ContentTypeException] -> ShowS
show :: ContentTypeException -> String
$cshow :: ContentTypeException -> String
showsPrec :: Int -> ContentTypeException -> ShowS
$cshowsPrec :: Int -> ContentTypeException -> ShowS
Show, Typeable)
instance Exception ContentTypeException
data JSONDecodeException
= JSONDecodeException
{ JSONDecodeException -> String
jsonDecodeExceptionMsg :: String
, JSONDecodeException -> String
jsonDecodeExceptionJSON :: String
} deriving (Int -> JSONDecodeException -> ShowS
[JSONDecodeException] -> ShowS
JSONDecodeException -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [JSONDecodeException] -> ShowS
$cshowList :: [JSONDecodeException] -> ShowS
show :: JSONDecodeException -> String
$cshow :: JSONDecodeException -> String
showsPrec :: Int -> JSONDecodeException -> ShowS
$cshowsPrec :: Int -> JSONDecodeException -> ShowS
Show, Typeable)
instance Exception JSONDecodeException
data = String
deriving (Int -> HeaderNotFoundException -> ShowS
[HeaderNotFoundException] -> ShowS
HeaderNotFoundException -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [HeaderNotFoundException] -> ShowS
$cshowList :: [HeaderNotFoundException] -> ShowS
show :: HeaderNotFoundException -> String
$cshow :: HeaderNotFoundException -> String
showsPrec :: Int -> HeaderNotFoundException -> ShowS
$cshowsPrec :: Int -> HeaderNotFoundException -> ShowS
Show, Typeable)
instance Exception HeaderNotFoundException
data MattermostError = MattermostError
{ MattermostError -> Text
mattermostErrorId :: T.Text
, MattermostError -> Text
mattermostErrorMessage :: T.Text
, MattermostError -> Text
mattermostErrorRequestId :: T.Text
, MattermostError -> Int
mattermostErrorStatusCode :: Int
, MattermostError -> Bool
mattermostErrorIsOAuth :: Bool
} deriving (Int -> MattermostError -> ShowS
[MattermostError] -> ShowS
MattermostError -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [MattermostError] -> ShowS
$cshowList :: [MattermostError] -> ShowS
show :: MattermostError -> String
$cshow :: MattermostError -> String
showsPrec :: Int -> MattermostError -> ShowS
$cshowsPrec :: Int -> MattermostError -> ShowS
Show, Typeable)
instance Exception MattermostError
instance A.FromJSON MattermostError where
parseJSON :: Value -> Parser MattermostError
parseJSON = forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"MattermostError" forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Text
mattermostErrorId <- Object
o forall a. FromJSON a => Object -> Key -> Parser a
A..: Key
"id"
Text
mattermostErrorMessage <- Object
o forall a. FromJSON a => Object -> Key -> Parser a
A..: Key
"message"
Text
mattermostErrorRequestId <- Object
o forall a. FromJSON a => Object -> Key -> Parser a
A..: Key
"request_id"
Int
mattermostErrorStatusCode <- Object
o forall a. FromJSON a => Object -> Key -> Parser a
A..: Key
"status_code"
Bool
mattermostErrorIsOAuth <- Object
o forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"is_oauth" forall a. Parser (Maybe a) -> a -> Parser a
A..!= Bool
False
forall (m :: * -> *) a. Monad m => a -> m a
return MattermostError { Bool
Int
Text
mattermostErrorIsOAuth :: Bool
mattermostErrorStatusCode :: Int
mattermostErrorRequestId :: Text
mattermostErrorMessage :: Text
mattermostErrorId :: Text
mattermostErrorIsOAuth :: Bool
mattermostErrorStatusCode :: Int
mattermostErrorRequestId :: Text
mattermostErrorMessage :: Text
mattermostErrorId :: Text
.. }
data MattermostServerError = MattermostServerError T.Text
deriving (Int -> MattermostServerError -> ShowS
[MattermostServerError] -> ShowS
MattermostServerError -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [MattermostServerError] -> ShowS
$cshowList :: [MattermostServerError] -> ShowS
show :: MattermostServerError -> String
$cshow :: MattermostServerError -> String
showsPrec :: Int -> MattermostServerError -> ShowS
$cshowsPrec :: Int -> MattermostServerError -> ShowS
Show, Typeable)
instance Exception MattermostServerError
data RateLimitException =
RateLimitException { RateLimitException -> Maybe Int
rateLimitExceptionLimit :: Maybe Int
, RateLimitException -> Maybe Int
rateLimitExceptionRemaining :: Maybe Int
, RateLimitException -> Maybe Int
rateLimitExceptionReset :: Maybe Int
}
deriving (Int -> RateLimitException -> ShowS
[RateLimitException] -> ShowS
RateLimitException -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RateLimitException] -> ShowS
$cshowList :: [RateLimitException] -> ShowS
show :: RateLimitException -> String
$cshow :: RateLimitException -> String
showsPrec :: Int -> RateLimitException -> ShowS
$cshowsPrec :: Int -> RateLimitException -> ShowS
Show, Typeable)
instance Exception RateLimitException
data HTTPResponseException = HTTPResponseException String
deriving (Int -> HTTPResponseException -> ShowS
[HTTPResponseException] -> ShowS
HTTPResponseException -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [HTTPResponseException] -> ShowS
$cshowList :: [HTTPResponseException] -> ShowS
show :: HTTPResponseException -> String
$cshow :: HTTPResponseException -> String
showsPrec :: Int -> HTTPResponseException -> ShowS
$cshowsPrec :: Int -> HTTPResponseException -> ShowS
Show, Typeable)
instance Exception HTTPResponseException
data ConnectionException = ConnectionException ConnError
deriving (Int -> ConnectionException -> ShowS
[ConnectionException] -> ShowS
ConnectionException -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ConnectionException] -> ShowS
$cshowList :: [ConnectionException] -> ShowS
show :: ConnectionException -> String
$cshow :: ConnectionException -> String
showsPrec :: Int -> ConnectionException -> ShowS
$cshowsPrec :: Int -> ConnectionException -> ShowS
Show, Typeable)
instance Exception ConnectionException