git.iko.soy/typeable/http-api-data
on master help sign in
Fix runReader (should consume all of the input)
commit1c0f937910fc79fa1a81c05ab3e21962d27d7331 authorNickolay Kudasov <nickolay.kudasov@gmail.com> dateSun 4 Oct 2015, 04:10 (11 years ago) parent8dc43fe
1 file changed+6−3
Web/HttpApiData.hs+6−3
Web/HttpApiData.hs+6−3
@@ -19,8 +19,6 @@ module Web.HttpApiData (
1919 readEitherUrlPiece,
2020) where
2121
22−import Control.Arrow ((+++))
23−
2422import Data.Monoid
2523import Data.ByteString (ByteString)
2624
@@ -93,7 +91,12 @@ readEitherUrlPiece = parseMaybeHttpApiData readMaybeUrlPiece
9391
9492-- | Run @'Reader'@ as HTTP API data parser.
9593runReader :: 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 <> "'")
97100
98101instance ToHttpApiData Bool where toUrlPiece = showUrlPiece
99102instance ToHttpApiData Double where toUrlPiece = showUrlPiece