{-# LANGUAGE DeriveAnyClass #-}
{-|
Module: IHP.Router.Types
Copyright: (c) digitally induced GmbH, 2020
-}
module IHP.Router.Types where

import IHP.Prelude
import Network.HTTP.Types.Method

data TypedAutoRouteError
    = BadType
        { TypedAutoRouteError -> ByteString
expectedType :: !ByteString
        , TypedAutoRouteError -> Maybe ByteString
value :: !(Maybe ByteString)
        , TypedAutoRouteError -> ByteString
field :: !ByteString
        }
    | TooFewArguments
    | NotMatched
    -- | Thrown when 'IHP.RouterSupport.parseUUIDArgument', 'IHP.RouterSupport.parseIntArgument', etc. get passed an invalid value
    --
    -- Let's say we have a @ShowProjectAction { id :: Id Project }@.
    --
    -- When opening @/ShowProject?projectId=ab55d579-80cd-4608-9a8f-c76dea6c2332@ everything is fine.
    -- But when opening @/ShowProject?projectId=not-an-uuid@ this exception will be thrown.
    | NoConstructorMatched
        { expectedType :: !ByteString
        , value :: !(Maybe ByteString)
        , field :: !ByteString
        }
    deriving (Int -> TypedAutoRouteError -> ShowS
[TypedAutoRouteError] -> ShowS
TypedAutoRouteError -> String
(Int -> TypedAutoRouteError -> ShowS)
-> (TypedAutoRouteError -> String)
-> ([TypedAutoRouteError] -> ShowS)
-> Show TypedAutoRouteError
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TypedAutoRouteError -> ShowS
showsPrec :: Int -> TypedAutoRouteError -> ShowS
$cshow :: TypedAutoRouteError -> String
show :: TypedAutoRouteError -> String
$cshowList :: [TypedAutoRouteError] -> ShowS
showList :: [TypedAutoRouteError] -> ShowS
Show, Show TypedAutoRouteError
Typeable TypedAutoRouteError
(Typeable TypedAutoRouteError, Show TypedAutoRouteError) =>
(TypedAutoRouteError -> SomeException)
-> (SomeException -> Maybe TypedAutoRouteError)
-> (TypedAutoRouteError -> String)
-> Exception TypedAutoRouteError
SomeException -> Maybe TypedAutoRouteError
TypedAutoRouteError -> String
TypedAutoRouteError -> SomeException
forall e.
(Typeable e, Show e) =>
(e -> SomeException)
-> (SomeException -> Maybe e) -> (e -> String) -> Exception e
$ctoException :: TypedAutoRouteError -> SomeException
toException :: TypedAutoRouteError -> SomeException
$cfromException :: SomeException -> Maybe TypedAutoRouteError
fromException :: SomeException -> Maybe TypedAutoRouteError
$cdisplayException :: TypedAutoRouteError -> String
displayException :: TypedAutoRouteError -> String
Exception)

-- | Thrown e.g. a @CreateProjectAction@ is called from a GET request
--
data UnexpectedMethodException
    = UnexpectedMethodException
    { UnexpectedMethodException -> [StdMethod]
allowedMethods :: [StdMethod]
    , UnexpectedMethodException -> StdMethod
method :: StdMethod
    }
    deriving (Int -> UnexpectedMethodException -> ShowS
[UnexpectedMethodException] -> ShowS
UnexpectedMethodException -> String
(Int -> UnexpectedMethodException -> ShowS)
-> (UnexpectedMethodException -> String)
-> ([UnexpectedMethodException] -> ShowS)
-> Show UnexpectedMethodException
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> UnexpectedMethodException -> ShowS
showsPrec :: Int -> UnexpectedMethodException -> ShowS
$cshow :: UnexpectedMethodException -> String
show :: UnexpectedMethodException -> String
$cshowList :: [UnexpectedMethodException] -> ShowS
showList :: [UnexpectedMethodException] -> ShowS
Show, Show UnexpectedMethodException
Typeable UnexpectedMethodException
(Typeable UnexpectedMethodException,
 Show UnexpectedMethodException) =>
(UnexpectedMethodException -> SomeException)
-> (SomeException -> Maybe UnexpectedMethodException)
-> (UnexpectedMethodException -> String)
-> Exception UnexpectedMethodException
SomeException -> Maybe UnexpectedMethodException
UnexpectedMethodException -> String
UnexpectedMethodException -> SomeException
forall e.
(Typeable e, Show e) =>
(e -> SomeException)
-> (SomeException -> Maybe e) -> (e -> String) -> Exception e
$ctoException :: UnexpectedMethodException -> SomeException
toException :: UnexpectedMethodException -> SomeException
$cfromException :: SomeException -> Maybe UnexpectedMethodException
fromException :: SomeException -> Maybe UnexpectedMethodException
$cdisplayException :: UnexpectedMethodException -> String
displayException :: UnexpectedMethodException -> String
Exception)