@@ -53,17 +53,22 @@ data ElmOptions = ElmOptions
5353 argument.
5454 -}
5555 urlPrefix :: UrlPrefix
56− , elmTypeAlterations :: (EType -> EType)
56+ , elmTypeAlterations :: (EType -> EType)
5757 -- ^ Alterations to perform on ETypes before code generation.
5858 , elmAlterations :: (ETypeDef -> ETypeDef)
5959 -- ^ Alterations to perform on ETypeDefs before code generation.
60− , elmToString :: (EType -> Text)
60+ , elmToString :: (EType -> Text)
6161 -- ^ Elm functions creating a string from a given type.
6262 , emptyResponseElmTypes :: [EType]
6363 -- ^ Types that represent an empty Http response.
6464 , stringElmTypes :: [EType]
6565 -- ^ Types that represent a String.
6666 , expectJsonMethod :: Text
67+ -- ^ The function to use for JSON responses.
68+ , expectStringMethod :: Text
69+ -- ^ The function to use for string responses.
70+ , httpErrorType :: Text
71+ -- ^ The type to use for Http errors.
6772 }
6873
6974
@@ -87,6 +92,9 @@ The default options are:
8792> , stringElmTypes =
8893> [ getType (Proxy :: Proxy String)
8994> , getType (Proxy :: Proxy T.Text) ]
95+> , expectJsonMethod = "Http.expectJson"
96+> , expectStringMethod = "Http.expectString"
97+> , httpErrorType = "Http.Error"
9098> }
9199-}
92100defElmOptions :: ElmOptions
@@ -103,6 +111,8 @@ defElmOptions = ElmOptions
103111 , toElmType (Proxy :: Proxy T.Text)
104112 ]
105113 , expectJsonMethod = "Http.expectJson"
114+ , expectStringMethod = "Http.expectString"
115+ , httpErrorType = "Http.Error"
106116 }
107117
108118
@@ -311,7 +321,7 @@ mkTypeSignature opts request =
311321 toMsgType :: Maybe Doc
312322 toMsgType = do
313323 result <- fmap elmTypeRef $ request ^. F.reqReturnType
314− Just ("(Result Http.Error " <+> parens result <+> " -> msg)")
324+ Just ("(Result" <+> stext (httpErrorType opts) <+> parens result <+> "-> msg)")
315325
316326 returnType :: Maybe Doc
317327 returnType = do
@@ -503,11 +513,11 @@ mkRequest opts request =
503513 | isEmptyType opts $ (elmTypeAlterations opts) elmTypeExpr
504514 -- let elmConstructor = T.pack (renderElm elmTypeExpr)
505515 ->
506− "Http.expectString " <> line <+> indent i "(\\x -> case x of" <> line <+>
516+ stext (expectStringMethod opts) <> line <+> indent i "(\\x -> case x of" <> line <+>
507517 indent i "Err e -> toMsg (Err e)" <> line <+>
508518 indent i "Ok _ -> toMsg (Ok ()))"
509519 Just elmTypeExpr ->
510− stext (expectJsonMethod opts) <+> " toMsg" <+> renderDecoderName ((elmTypeAlterations opts) elmTypeExpr)
520+ stext (expectJsonMethod opts) <+> "toMsg" <+> renderDecoderName ((elmTypeAlterations opts) elmTypeExpr)
511521 Nothing -> error "mkHttpRequest: no reqReturnType?"
512522 -- case request ^. F.reqReturnType of
513523 -- Just elmTypeExpr | isEmptyType opts elmTypeExpr ->