diff --git a/src/DataSource.elm b/src/DataSource.elm index 86063688..55521466 100644 --- a/src/DataSource.elm +++ b/src/DataSource.elm @@ -83,7 +83,6 @@ So it's best to use that mental model to avoid confusion. -} -import Dict exposing (Dict) import Pages.Internal.ApplicationType exposing (ApplicationType) import Pages.Internal.StaticHttpBody as Body import Pages.StaticHttp.Request as HashRequest diff --git a/src/DataSource/Http.elm b/src/DataSource/Http.elm index dfe742ab..aaab7edb 100644 --- a/src/DataSource/Http.elm +++ b/src/DataSource/Http.elm @@ -52,7 +52,6 @@ and describe your use case! -} import DataSource exposing (DataSource) -import Dict import Json.Decode import Json.Encode as Encode import Pages.Internal.StaticHttpBody as Body diff --git a/src/Pages/Internal/Platform/StaticResponses.elm b/src/Pages/Internal/Platform/StaticResponses.elm index b093b783..18638c5b 100644 --- a/src/Pages/Internal/Platform/StaticResponses.elm +++ b/src/Pages/Internal/Platform/StaticResponses.elm @@ -266,43 +266,6 @@ nextStep config ({ allRawResponses, errors } as model) maybeRoutes = else True ) - - failedRequests : List BuildError - failedRequests = - staticResponses - |> Dict.toList - |> List.concatMap - (\( path, NotFetched request _ ) -> - let - staticRequestsStatus : StaticHttpRequest.Status () - staticRequestsStatus = - StaticHttpRequest.cacheRequestResolution - ApplicationType.Cli - request - usableRawResponses - - usableRawResponses : RequestsAndPending - usableRawResponses = - allRawResponses - - maybePermanentError : Maybe StaticHttpRequest.Error - maybePermanentError = - case staticRequestsStatus of - StaticHttpRequest.HasPermanentError theError -> - Just theError - - _ -> - Nothing - - decoderErrors : List BuildError - decoderErrors = - maybePermanentError - |> Maybe.map (StaticHttpRequest.toBuildError path) - |> Maybe.map List.singleton - |> Maybe.withDefault [] - in - decoderErrors - ) in if pendingRequests then let @@ -383,40 +346,79 @@ nextStep config ({ allRawResponses, errors } as model) maybeRoutes = -- -- Ok okSiteStaticData -> let - generatedFiles : List (Result String { path : List String, content : String }) - generatedFiles = - resolvedGenerateFilesResult |> Result.withDefault [] - - resolvedGenerateFilesResult : Result StaticHttpRequest.Error (List (Result String { path : List String, content : String })) - resolvedGenerateFilesResult = - StaticHttpRequest.resolve ApplicationType.Cli - (buildTimeFilesRequest config) - (allRawResponses |> Dict.Extra.filterMap (\_ value -> Just value)) - allErrors : List BuildError allErrors = + let + failedRequests : List BuildError + failedRequests = + staticResponses + |> Dict.toList + |> List.concatMap + (\( path, NotFetched request _ ) -> + let + staticRequestsStatus : StaticHttpRequest.Status () + staticRequestsStatus = + StaticHttpRequest.cacheRequestResolution + ApplicationType.Cli + request + usableRawResponses + + usableRawResponses : RequestsAndPending + usableRawResponses = + allRawResponses + + maybePermanentError : Maybe StaticHttpRequest.Error + maybePermanentError = + case staticRequestsStatus of + StaticHttpRequest.HasPermanentError theError -> + Just theError + + _ -> + Nothing + + decoderErrors : List BuildError + decoderErrors = + maybePermanentError + |> Maybe.map (StaticHttpRequest.toBuildError path) + |> Maybe.map List.singleton + |> Maybe.withDefault [] + in + decoderErrors + ) + + generatedFileErrors : List BuildError + generatedFileErrors = + let + generatedFiles : List (Result String { path : List String, content : String }) + generatedFiles = + resolvedGenerateFilesResult |> Result.withDefault [] + + resolvedGenerateFilesResult : Result StaticHttpRequest.Error (List (Result String { path : List String, content : String })) + resolvedGenerateFilesResult = + StaticHttpRequest.resolve ApplicationType.Cli + (buildTimeFilesRequest config) + (allRawResponses |> Dict.Extra.filterMap (\_ value -> Just value)) + in + generatedFiles + |> List.filterMap + (\result -> + case result of + Ok _ -> + Nothing + + Err error_ -> + Just + { title = "Generate Files Error" + , message = + [ Terminal.text "I encountered an Err from your generateFiles function. Message:\n" + , Terminal.text <| "Error: " ++ error_ + ] + , path = "Site.elm" + , fatal = True + } + ) + in errors ++ failedRequests ++ generatedFileErrors - - generatedFileErrors : List BuildError - generatedFileErrors = - generatedFiles - |> List.filterMap - (\result -> - case result of - Ok _ -> - Nothing - - Err error_ -> - Just - { title = "Generate Files Error" - , message = - [ Terminal.text "I encountered an Err from your generateFiles function. Message:\n" - , Terminal.text <| "Error: " ++ error_ - ] - , path = "Site.elm" - , fatal = True - } - ) in ( model.staticResponses , case encode allRawResponses staticResponses of @@ -462,6 +464,44 @@ nextStep config ({ allRawResponses, errors } as model) maybeRoutes = ) Err error_ -> + let + failedRequests : List BuildError + failedRequests = + staticResponses + |> Dict.toList + |> List.concatMap + (\( path, NotFetched request _ ) -> + let + staticRequestsStatus : StaticHttpRequest.Status () + staticRequestsStatus = + StaticHttpRequest.cacheRequestResolution + ApplicationType.Cli + request + usableRawResponses + + usableRawResponses : RequestsAndPending + usableRawResponses = + allRawResponses + + maybePermanentError : Maybe StaticHttpRequest.Error + maybePermanentError = + case staticRequestsStatus of + StaticHttpRequest.HasPermanentError theError -> + Just theError + + _ -> + Nothing + + decoderErrors : List BuildError + decoderErrors = + maybePermanentError + |> Maybe.map (StaticHttpRequest.toBuildError path) + |> Maybe.map List.singleton + |> Maybe.withDefault [] + in + decoderErrors + ) + in ( model.staticResponses , Finish (Errors <|