rest-types 1.10.2 → 1.11
raw patch · 4 files changed
+77/−16 lines, 4 files
Files
- CHANGELOG.md +9/−3
- rest-types.cabal +5/−4
- src/Rest/Types/Error.hs +35/−9
- src/Rest/Types/Info.hs +28/−0
CHANGELOG.md view
@@ -1,5 +1,11 @@ # Changelog +### 1.11++* Added `Rest.Types.Error.ToResponseCode` for getting the response codes of errors.+* Removed `responseCode` from `Rest.Types.Error.DomainReason`, use `toResponseCode` instead.+* Added `Rest.Types.Info`, moved from `rest-core`.+ ### 1.10.2 * Add `Functor`, `Foldable` and `Traversable` instances for the types@@ -11,15 +17,15 @@ #### 1.10.0.3 -* Use `JSONSchema` `Any` type instead of `Choice []`+* Use `JSONSchema` `Any` type instead of `Choice []`. #### 1.10.0.2 -* Use `rest-stringmap == 0.2.*`+* Use `rest-stringmap == 0.2.*`. #### 1.10.0.1 -* Allow `mtl == 2.2.*`+* Allow `mtl == 2.2.*`. ## 1.10
rest-types.cabal view
@@ -1,5 +1,5 @@ name: rest-types-version: 1.10.2+version: 1.11 description: Silk Rest Framework Types synopsis: Silk Rest Framework Types maintainer: code@silk.co@@ -23,17 +23,18 @@ exposed-modules: Rest.Types.Container Rest.Types.Container.Resource+ Rest.Types.Info Rest.Types.Error Rest.Types.ShowUrl build-depends: base == 4.* , aeson >= 0.7 && < 0.9- , generic-aeson == 0.1.*+ , generic-aeson >= 0.1 && < 0.3 , hxt >= 9.2 && < 9.4- , json-schema == 0.6.*+ , json-schema >= 0.6 && < 0.8 , mtl >= 2.0 && < 2.3 , regular == 0.3.* , regular-xmlpickler == 0.2.* , rest-stringmap == 0.2.*- , text >= 0.11 && < 1.2+ , text >= 0.11 && < 1.3 , uuid >= 1.2 && < 1.4
src/Rest/Types/Error.hs view
@@ -20,6 +20,7 @@ , Reason_ , Reason(..) , SomeReason(..)+ , ToResponseCode(..) ) where import Control.Monad.Error@@ -46,20 +47,16 @@ | UnsupportedFormat String deriving (Eq, Generic, Show) -data DomainReason a = DomainReason { responseCode :: Int, reason :: a }- deriving (Eq, Generic, Functor, Foldable, Traversable)--instance Show a => Show (DomainReason a) where- showsPrec a (DomainReason _ e) = showParen (a >= 11) (showString "Domain " . showsPrec 11 e)+newtype DomainReason a = DomainReason { reason :: a }+ deriving (Eq, Generic, Functor, Foldable, Show, Traversable) instance XmlPickler a => XmlPickler (DomainReason a) where- xpickle = xpWrap (DomainReason (error "No error function defined for DomainReason parsed from JSON"), reason) xpickle+ xpickle = xpWrap (DomainReason, reason) xpickle instance ToJSON a => ToJSON (DomainReason a) where- toJSON (DomainReason _ e) = toJSON e+ toJSON (DomainReason e) = toJSON e instance FromJSON a => FromJSON (DomainReason a) where- parseJSON = fmap (DomainReason (error "No error function defined for DomainReason parsed from JSON")) . parseJSON-+ parseJSON = fmap DomainReason . parseJSON instance JSONSchema a => JSONSchema (DomainReason a) where schema = schema . fmap reason@@ -150,3 +147,32 @@ instance JSONSchema SomeReason where schema _ = JSONSchema.Any++-- | The response code that should be given for a type.+-- This is currently only used for errors.+class ToResponseCode a where+ toResponseCode :: a -> Int++-- This instance shouldn't be here, and instead the None dictionary in+-- Rest.Dictionary.Types should have type Dicts f Void.+instance ToResponseCode () where+ toResponseCode () = 500++instance ToResponseCode a => ToResponseCode (Reason a) where+ toResponseCode e =+ case e of+ NotFound -> 404+ UnsupportedRoute -> 404+ UnsupportedMethod -> 404+ UnsupportedVersion -> 404+ NotAllowed -> 403+ AuthenticationFailed -> 401+ Busy -> 503+ Gone -> 410+ OutputError (UnsupportedFormat _) -> 406+ InputError _ -> 400+ OutputError _ -> 500+ IdentError _ -> 400+ HeaderError _ -> 400+ ParamError _ -> 400+ CustomReason (DomainReason a) -> toResponseCode a
+ src/Rest/Types/Info.hs view
@@ -0,0 +1,28 @@+{-# LANGUAGE+ FlexibleInstances+ , TypeSynonymInstances+ #-}+-- | Module facilitating informative inspection of datatypes.+module Rest.Types.Info where++import Data.Text (Text)+import Data.Typeable++-- | Type class representing information about the read/show function on a data+-- type.+class Typeable a => Info a where+ describe :: proxy a -> String+ example :: proxy a -> String+ example _ = ""++instance Info String where+ describe _ = "string"++instance Info Text where+ describe _ = "string"++instance Info Int where+ describe _ = "integer"++instance Info Integer where+ describe _ = "integer"