gingersnap 0.2.0.1 → 0.2.1.0
raw patch · 3 files changed
+18/−14 lines, 3 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- Gingersnap.Core: DefaultApiErr_Custom :: Status -> String -> DefaultApiErr
+ Gingersnap.Core: DefaultApiErr_Custom :: Status -> String -> [(Text, Value)] -> DefaultApiErr
Files
- README.md +14/−10
- gingersnap.cabal +1/−1
- src/Gingersnap/Core.hs +3/−3
README.md view
@@ -18,7 +18,7 @@ ```haskell {-# LANGUAGE DeriveGeneric, OverloadedStrings #-} -import Data.Aeson (ToJSON)+import Data.Aeson (ToJSON, (.=)) import Database.PostgreSQL.Simple -- For our automatic JSON instance: import GHC.Generics (Generic)@@ -182,23 +182,27 @@ three :: Ctx -> Snap () three ctx = inTransaction ctx $ \conn -> do- [Only d] <- query_ conn " SELECT random () "- pure $ if d >= (0.5 :: Double)- then rspGood d- else rspBad $ DefaultApiErr_Custom internalServerError500 $- "number too small: "++ show d+ [Only n] <- query_ conn " SELECT random () "+ pure $ if n >= (0.5 :: Double)+ then rspGood n+ else rspBad $+ DefaultApiErr_Custom+ internalServerError500+ "'n' too small"+ [("n" .= n)] ``` $ curl -v 'localhost:8000/three' [...]- < HTTP/1.1 500 Internal Server Error+ < HTTP/1.1 200 OK [...]- {"errorCode":6,"errorVals":[],"errorMessage":"number too small: 0.163489528931677"}+ {"result":0.594665706157684}+ $ curl -v 'localhost:8000/three' [...]- < HTTP/1.1 200 OK+ < HTTP/1.1 500 Internal Server Error [...]- {"result":0.594665706157684}+ {"errorCode":6,"errorVals":[["n",0.250084751285613]],"errorMessage":"'n' too small"} If you'd like to write your own `ApiErr` instance (which you probably should if you're building something "real":
gingersnap.cabal view
@@ -1,5 +1,5 @@ name: gingersnap-version: 0.2.0.1+version: 0.2.1.0 synopsis: snap-core + aeson + postgresql-simple = delicious description: JSON API idioms for snap-core, preventing DB connection leaks.
src/Gingersnap/Core.hs view
@@ -149,7 +149,7 @@ | DefaultApiErr_RequestNotJSONObject | DefaultApiErr_MalformedRequestValue Text JSON.Value | DefaultApiErr_UnexpectedError Text- | DefaultApiErr_Custom HTTP.Status String+ | DefaultApiErr_Custom HTTP.Status String [(Text, JSON.Value)] deriving (Show, Eq) instance ApiErr DefaultApiErr where@@ -193,8 +193,8 @@ (5, HTTP.unprocessableEntity422, "Malformed value: "++show k, [ "key" .= k, "value" .= v ])- DefaultApiErr_Custom s t ->- (6, s, t, [])+ DefaultApiErr_Custom s t vals ->+ (6, s, t, vals) -- | How we construct responses. You probably don't want to be constructing or -- inspecting them by hand; instead you can use 'rspGood', 'rspBadRollback', etc.