@@ -27,6 +27,8 @@ toApplication ra request respond = do
2727 respond $ responseLBS notFound404 [] "not found"
2828 routingRespond (Left WrongMethod) =
2929 respond $ responseLBS methodNotAllowed405 [] "method not allowed"
30+ routingRespond (Left InvalidBody) =
31+ respond $ responseLBS badRequest400 [] "Invalid JSON in request body"
3032 routingRespond (Right response) =
3133 respond response
3234
@@ -34,18 +36,25 @@ toApplication ra request respond = do
3436data RouteMismatch =
3537 NotFound -- ^ the usual "not found" error
3638 | WrongMethod -- ^ a more informative "you just got the HTTP method wrong" error
39+ | InvalidBody -- ^ an even more informative "you json request body wasn't valid" error
3740 deriving (Eq, Show)
3841
3942-- |
4043-- @
41−-- 'NotFound' <> x = x
42−-- 'WrongMethod' <> _ = 'WrongMethod'
44+-- > mempty = NotFound
45+-- >
46+-- > NotFound `mappend` x = x
47+-- > WrongMethod `mappend` InvalidBody = InvalidBody
48+-- > WrongMethod `mappend` _ = WrongMethod
49+-- > InvalidBody `mappend` _ = InvalidBody
4350-- @
4451instance Monoid RouteMismatch where
4552 mempty = NotFound
4653
47− NotFound `mappend` x = x
48− WrongMethod `mappend` _ = WrongMethod
54+ NotFound `mappend` x = x
55+ WrongMethod `mappend` InvalidBody = InvalidBody
56+ WrongMethod `mappend` _ = WrongMethod
57+ InvalidBody `mappend` _ = InvalidBody
4958
5059-- | A wrapper around @'Either' 'RouteMismatch' a@.
5160newtype RouteResult a =