Terminate with port message after HTTP error.

This commit is contained in:
Dillon Kearns 2019-11-02 13:14:09 -07:00
parent d4988dffe2
commit e6f8b691eb
2 changed files with 21 additions and 13 deletions

View File

@ -637,6 +637,18 @@ sendStaticResponsesIfDone secrets allRawResponses errors staticResponses manifes
|> Maybe.map (\_ -> True)
|> Maybe.withDefault False
hasPermanentHttpError =
errors
|> List.any
(\error ->
case error of
FailedStaticHttpRequestError _ ->
True
_ ->
False
)
( allUrlsKnown, knownUrlsToFetch ) =
StaticHttpRequest.resolveUrls request
(rawResponses |> Dict.map (\key value -> value |> Result.withDefault ""))
@ -645,7 +657,7 @@ sendStaticResponsesIfDone secrets allRawResponses errors staticResponses manifes
(knownUrlsToFetch |> List.map Pages.Internal.Secrets.useFakeSecrets |> Set.fromList |> Set.size)
== (rawResponses |> Dict.keys |> List.length)
in
if hasPermanentError || (allUrlsKnown && fetchedAllKnownUrls) then
if hasPermanentHttpError || hasPermanentError || (allUrlsKnown && fetchedAllKnownUrls) then
False
else

View File

@ -18,6 +18,7 @@ import SimulatedEffect.Cmd
import SimulatedEffect.Http
import SimulatedEffect.Ports
import StaticHttp
import TerminalText as Terminal
import Test exposing (Test, describe, only, test)
import Test.Http
@ -239,18 +240,13 @@ The user should get this message from the CLI."""
"toJsPort"
(Codec.decoder Main.toJsCodec)
(Expect.equal
[ Errors
"""\u{001B}[36m-- FAILED STATIC HTTP ERROR ----------------------------------------------------- elm-pages\u{001B}[0m
/elm-pages
Problem with the given value:
{
"stargazer_count": 86
}
The user should get this message from the CLI."""
[ Errors <|
Terminal.toString
[ Terminal.cyan <| Terminal.text "-- FAILED STATIC HTTP ERROR ----------------------------------------------------- elm-pages"
, Terminal.text "\n\nI got an error making an HTTP request to this URL: "
, Terminal.yellow <| Terminal.text "https://api.github.com/repos/dillonkearns/elm-pages"
, Terminal.text "\n\nBad status: 404"
]
]
)
, test "uses real secrets to perform request and masked secrets to store and lookup response" <|