Inline error to string function for static http requests.

This commit is contained in:
Dillon Kearns 2019-12-07 06:35:36 -08:00
parent 39d9f84783
commit 79142c7be1
3 changed files with 31 additions and 21 deletions

View File

@ -623,6 +623,16 @@ printKeys message dict =
dict dict
isJust : Maybe a -> Bool
isJust maybeValue =
case maybeValue of
Just _ ->
True
Nothing ->
False
sendStaticResponsesIfDone : Mode -> SecretsDict -> Dict String (Maybe String) -> List BuildError -> StaticResponses -> Manifest.Config pathKey -> ( Dict String (Maybe String), Effect pathKey ) sendStaticResponsesIfDone : Mode -> SecretsDict -> Dict String (Maybe String) -> List BuildError -> StaticResponses -> Manifest.Config pathKey -> ( Dict String (Maybe String), Effect pathKey )
sendStaticResponsesIfDone mode secrets allRawResponses errors staticResponses manifest = sendStaticResponsesIfDone mode secrets allRawResponses errors staticResponses manifest =
let let
@ -646,8 +656,7 @@ sendStaticResponsesIfDone mode secrets allRawResponses errors staticResponses ma
hasPermanentError = hasPermanentError =
StaticHttpRequest.permanentError request usableRawResponses StaticHttpRequest.permanentError request usableRawResponses
|> Maybe.map (\_ -> True) |> isJust
|> Maybe.withDefault False
hasPermanentHttpError = hasPermanentHttpError =
not <| List.isEmpty errors not <| List.isEmpty errors

View File

@ -1,4 +1,4 @@
module Pages.StaticHttpRequest exposing (Error(..), Request(..), errorToString, permanentError, resolve, resolveUrls, strippedResponses, toBuildError, urls) module Pages.StaticHttpRequest exposing (Error(..), Request(..), permanentError, resolve, resolveUrls, strippedResponses, toBuildError, urls)
import BuildError exposing (BuildError) import BuildError exposing (BuildError)
import Dict exposing (Dict) import Dict exposing (Dict)
@ -26,16 +26,6 @@ strippedResponses request rawResponses =
rawResponses rawResponses
errorToString : Error -> String
errorToString error =
case error of
MissingHttpResponse string ->
string
DecoderError string ->
string
type Error type Error
= MissingHttpResponse String = MissingHttpResponse String
| DecoderError String | DecoderError String
@ -57,13 +47,24 @@ urls request =
toBuildError : String -> Error -> BuildError toBuildError : String -> Error -> BuildError
toBuildError path error = toBuildError path error =
{ title = "Static HTTP Error" case error of
, message = MissingHttpResponse missingKey ->
[ Terminal.text path { title = "Missing Http Response"
, Terminal.text "\n\n" , message =
, Terminal.text (errorToString error) [ Terminal.text path
] , Terminal.text "\n\n"
} , Terminal.text missingKey
]
}
DecoderError decodeErrorMessage ->
{ title = "Static Http Decoding Error"
, message =
[ Terminal.text path
, Terminal.text "\n\n"
, Terminal.text decodeErrorMessage
]
}
permanentError : Request value -> Dict String String -> Maybe Error permanentError : Request value -> Dict String String -> Maybe Error

View File

@ -490,7 +490,7 @@ all =
"toJsPort" "toJsPort"
(Codec.decoder Main.toJsCodec) (Codec.decoder Main.toJsCodec)
(expectErrorsPort (expectErrorsPort
"""-- STATIC HTTP ERROR ----------------------------------------------------- elm-pages """-- STATIC HTTP DECODING ERROR ----------------------------------------------------- elm-pages
/elm-pages /elm-pages