@@ -27,6 +27,8 @@ toApplication ra request respond = do
27 respond $ responseLBS notFound404 [] "not found"
27 respond $ responseLBS notFound404 [] "not found"
28 routingRespond (Left WrongMethod) =
28 routingRespond (Left WrongMethod) =
29 respond $ responseLBS methodNotAllowed405 [] "method not allowed"
29 respond $ responseLBS methodNotAllowed405 [] "method not allowed"
30+ routingRespond (Left InvalidBody) =
31+ respond $ responseLBS badRequest400 [] "Invalid JSON in request body"
30 routingRespond (Right response) =
32 routingRespond (Right response) =
31 respond response
33 respond response
@@ -34,18 +36,25 @@ toApplication ra request respond = do
34data RouteMismatch =
36data RouteMismatch =
35 NotFound -- ^ the usual "not found" error
37 NotFound -- ^ the usual "not found" error
36 | WrongMethod -- ^ a more informative "you just got the HTTP method wrong" error
38 | 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
37 deriving (Eq, Show)
40 deriving (Eq, Show)
44+-- > mempty = NotFound
41−-- 'NotFound' <> x = x
46+-- > NotFound `mappend` x = x
47+-- > WrongMethod `mappend` InvalidBody = InvalidBody
42−-- 'WrongMethod' <> _ = 'WrongMethod'
48+-- > WrongMethod `mappend` _ = WrongMethod
49+-- > InvalidBody `mappend` _ = InvalidBody
44instance Monoid RouteMismatch where
51instance Monoid RouteMismatch where
45 mempty = NotFound
52 mempty = NotFound
47− NotFound `mappend` x = x
54+ NotFound `mappend` x = x
48− WrongMethod `mappend` _ = WrongMethod
55+ WrongMethod `mappend` InvalidBody = InvalidBody
56+ WrongMethod `mappend` _ = WrongMethod
57+ InvalidBody `mappend` _ = InvalidBody
50-- | A wrapper around @'Either' 'RouteMismatch' a@.
59-- | A wrapper around @'Either' 'RouteMismatch' a@.
51newtype RouteResult a =
60newtype RouteResult a =