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
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 secrets allRawResponses errors staticResponses manifest =
let
@ -646,8 +656,7 @@ sendStaticResponsesIfDone mode secrets allRawResponses errors staticResponses ma
hasPermanentError =
StaticHttpRequest.permanentError request usableRawResponses
|> Maybe.map (\_ -> True)
|> Maybe.withDefault False
|> isJust
hasPermanentHttpError =
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 Dict exposing (Dict)
@ -26,16 +26,6 @@ strippedResponses request rawResponses =
rawResponses
errorToString : Error -> String
errorToString error =
case error of
MissingHttpResponse string ->
string
DecoderError string ->
string
type Error
= MissingHttpResponse String
| DecoderError String
@ -57,13 +47,24 @@ urls request =
toBuildError : String -> Error -> BuildError
toBuildError path error =
{ title = "Static HTTP Error"
, message =
[ Terminal.text path
, Terminal.text "\n\n"
, Terminal.text (errorToString error)
]
}
case error of
MissingHttpResponse missingKey ->
{ title = "Missing Http Response"
, message =
[ 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

View File

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