git.iko.soy/typeable/http-api-data
on master help sign in
Fix runReader (should consume all of the input)
1c0f937Nickolay Kudasov
Web/HttpApiData.hs+6−3
@@ -19,8 +19,6 @@ module Web.HttpApiData (
19 readEitherUrlPiece,
19 readEitherUrlPiece,
20) where
20) where
21
21
22−import Control.Arrow ((+++))
23−
24import Data.Monoid
22import Data.Monoid
25import Data.ByteString (ByteString)
23import Data.ByteString (ByteString)
26
24
@@ -93,7 +91,12 @@ readEitherUrlPiece = parseMaybeHttpApiData readMaybeUrlPiece
93
91
94-- | Run @'Reader'@ as HTTP API data parser.
92-- | Run @'Reader'@ as HTTP API data parser.
95runReader :: Reader a -> Text -> Either Text a
93runReader :: Reader a -> Text -> Either Text a
96−runReader reader = (Text.pack +++ fst) . reader
94+runReader reader input =
95+ case reader input of
96+ Left err -> Left (Text.pack err)
97+ Right (x, rest)
98+ | Text.null rest -> Right x
99+ | otherwise -> Left ("could not convert: `" <> input <> "'")
97
100
98instance ToHttpApiData Bool where toUrlPiece = showUrlPiece
101instance ToHttpApiData Bool where toUrlPiece = showUrlPiece
99instance ToHttpApiData Double where toUrlPiece = showUrlPiece
102instance ToHttpApiData Double where toUrlPiece = showUrlPiece