@@ -16,7 +16,7 @@ module Web.HttpApiData.Internal.FormUrlEncoded where
1616import Control.Applicative
1717#endif
1818
19−import Control.Arrow (first, left, second)
19+import Control.Arrow (first, second)
2020import Control.Monad.State
2121import qualified Data.ByteString.Lazy as BSL
2222import qualified Data.ByteString.Lazy.UTF8 as BSLUTF8
@@ -95,9 +95,9 @@ instance (ToHttpApiData f) => GToForm (K1 i f) where
9595-- | A type that can be converted from @application/x-www-form-urlencoded@,
9696-- with the possibility of failure.
9797class FromForm a where
98− fromForm :: Form -> Either String a
98+ fromForm :: Form -> Either T.Text a
9999 default fromForm :: (Generic a, GFromForm (Rep a))
100− => Form -> Either String a
100+ => Form -> Either T.Text a
101101 fromForm = genericFromForm
102102
103103instance FromForm Form where fromForm = return
@@ -105,11 +105,11 @@ instance FromForm [(T.Text, T.Text)] where fromForm = return . M.toList . unForm
105105instance FromForm (M.Map T.Text T.Text) where fromForm = return . unForm
106106
107107genericFromForm :: (Generic a, GFromForm (Rep a))
108− => Form -> Either String a
108+ => Form -> Either T.Text a
109109genericFromForm f = to <$> gFromForm f
110110
111111class GFromForm (f :: * -> *) where
112− gFromForm :: Form -> Either String (f x)
112+ gFromForm :: Form -> Either T.Text (f x)
113113
114114instance (GFromForm f, GFromForm g)
115115 => GFromForm (f :*: g) where
@@ -126,8 +126,8 @@ instance (GFromForm f, GFromForm g)
126126instance (Selector sel, FromHttpApiData f)
127127 => GFromForm (M1 S sel (K1 i f)) where
128128 gFromForm f = case M.lookup sel (unForm f) of
129− Nothing -> Left . T.unpack $ "Could not find key " <> sel
130− Just v -> left T.unpack $ M1 . K1 <$> parseQueryParam v
129+ Nothing -> Left $ "Could not find key " <> sel
130+ Just v -> M1 . K1 <$> parseQueryParam v
131131 where sel = T.pack $ selName (Proxy3 :: Proxy3 sel g p)
132132
133133instance (GFromForm f) => GFromForm (M1 D x f) where
@@ -145,19 +145,19 @@ encodeForm xs =
145145 encodePair (k, v) = escape k <> "=" <> escape v
146146 in BSL.intercalate "&" $ map encodePair $ toList xs
147147
148−decodeForm :: BSL.ByteString -> Either String Form
148+decodeForm :: BSL.ByteString -> Either T.Text Form
149149decodeForm "" = return mempty
150150decodeForm q = do
151151 let xs :: [T.Text]
152152 xs = T.splitOn "&" . decodeUtf8With lenientDecode . mconcat . BSL.toChunks $ q
153− parsePair :: T.Text -> Either String (T.Text, T.Text)
153+ parsePair :: T.Text -> Either T.Text (T.Text, T.Text)
154154 parsePair p =
155155 case T.splitOn "=" p of
156156 [k,v] -> return ( unescape k
157157 , unescape v
158158 )
159159 [k] -> return ( unescape k, "" )
160− _ -> Left $ "not a valid pair: " <> T.unpack p
160+ _ -> Left $ "not a valid pair: " <> p
161161 unescape :: T.Text -> T.Text
162162 unescape = T.pack . unEscapeString . T.unpack . T.intercalate "%20" . T.splitOn "+"
163163 toForm <$> mapM parsePair xs