Pass back strings as error message to JS.

This commit is contained in:
Dillon Kearns 2019-10-26 16:41:46 -07:00
parent d6b007f7ff
commit 84c9bc132c

View File

@ -37,7 +37,7 @@ import Url exposing (Url)
type ToJsPayload pathKey type ToJsPayload pathKey
= Errors (Dict String String) = Errors String
| Success (ToJsSuccessPayload pathKey) | Success (ToJsSuccessPayload pathKey)
@ -58,7 +58,7 @@ toJsCodec =
Success { pages, manifest } -> Success { pages, manifest } ->
success (ToJsSuccessPayload pages manifest) success (ToJsSuccessPayload pages manifest)
) )
|> Codec.variant1 "Errors" Errors (Codec.dict Codec.string) |> Codec.variant1 "Errors" Errors Codec.string
|> Codec.variant1 "Success" |> Codec.variant1 "Success"
Success Success
successCodec successCodec
@ -263,18 +263,19 @@ init toModel contentCache siteMetadata config cliMsgConstructor flags =
Ok _ -> Ok _ ->
( Model staticResponses secrets |> toModel ( Model staticResponses secrets |> toModel
, SendJsData , SendJsData
(Errors (Errors <|
(mapKeys pageErrorsToString
(\key -> "/" ++ String.join "/" key) (mapKeys
pageErrors (\key -> "/" ++ String.join "/" key)
) pageErrors
)
) )
) )
Err error -> Err error ->
( Model staticResponses Secrets.empty |> toModel ( Model staticResponses Secrets.empty |> toModel
, SendJsData , SendJsData
(Errors (Dict.fromList [ ( "", "Failed to parse flags: " ++ Decode.errorToString error ) ])) (Errors <| "Failed to parse flags: " ++ Decode.errorToString error)
) )
Nothing -> Nothing ->
@ -303,7 +304,7 @@ init toModel contentCache siteMetadata config cliMsgConstructor flags =
Err error -> Err error ->
( Model staticResponses secrets |> toModel ( Model staticResponses secrets |> toModel
, Errors Dict.empty |> SendJsData , Errors "TODO real error here" |> SendJsData
-- TODO send real error message -- TODO send real error message
) )
@ -314,11 +315,12 @@ init toModel contentCache siteMetadata config cliMsgConstructor flags =
Err error -> Err error ->
( Model Dict.empty secrets |> toModel ( Model Dict.empty secrets |> toModel
, SendJsData , SendJsData
(Errors (Errors <|
(mapKeys pageErrorsToString
(\key -> "/" ++ String.join "/" key) (mapKeys
error (\key -> "/" ++ String.join "/" key)
) error
)
) )
) )
-- (Errors error) -- (Errors error)
@ -332,10 +334,19 @@ init toModel contentCache siteMetadata config cliMsgConstructor flags =
Err error -> Err error ->
( Model Dict.empty Secrets.empty |> toModel ( Model Dict.empty Secrets.empty |> toModel
, SendJsData , SendJsData
(Errors (Dict.fromList [ ( "", "Failed to parse flags: " ++ Decode.errorToString error ) ])) (Errors <| "Failed to parse flags: " ++ Decode.errorToString error)
) )
type alias PageErrors =
Dict String String
pageErrorsToString : PageErrors -> String
pageErrorsToString pageErrors =
"TODO"
update : update :
Result (List String) (List ( PagePath pathKey, metadata )) Result (List String) (List ( PagePath pathKey, metadata ))
-> ->
@ -525,7 +536,7 @@ sendStaticResponsesIfDone staticResponses manifest =
) )
else else
Errors failedRequests Errors <| pageErrorsToString failedRequests
) )