From ad3d68cc9b0c456ee59ec0fb4fcbbe165cf9e981 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Mon, 6 Feb 2023 09:52:59 -0800 Subject: [PATCH] Use local artificial error API to avoid rate limit. --- examples/end-to-end/app/Api.elm | 17 +++++++++++++++++ examples/end-to-end/src/Test/HttpRequests.elm | 4 ++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/examples/end-to-end/app/Api.elm b/examples/end-to-end/app/Api.elm index 263cb49b..f67eb3e0 100644 --- a/examples/end-to-end/app/Api.elm +++ b/examples/end-to-end/app/Api.elm @@ -56,9 +56,26 @@ routes getStaticRoutes htmlToString = , requestPrinter , xmlDecoder , multipleContentTypes + , errorRoute ] +errorRoute : ApiRoute ApiRoute.Response +errorRoute = + ApiRoute.succeed + (\errorCode -> + Request.succeed + (Response.plainText ("Here is the error code you requested (" ++ errorCode ++ ")") + |> Response.withStatusCode (String.toInt errorCode |> Maybe.withDefault 500) + |> BackendTask.succeed + ) + ) + |> ApiRoute.literal "error-code" + |> ApiRoute.slash + |> ApiRoute.capture + |> ApiRoute.serverRender + + xmlDecoder : ApiRoute ApiRoute.Response xmlDecoder = let diff --git a/examples/end-to-end/src/Test/HttpRequests.elm b/examples/end-to-end/src/Test/HttpRequests.elm index 1af53a70..8cc1829a 100644 --- a/examples/end-to-end/src/Test/HttpRequests.elm +++ b/examples/end-to-end/src/Test/HttpRequests.elm @@ -10,7 +10,7 @@ import Test exposing (Test) all : BackendTask FatalError Test all = - [ BackendTask.Http.get "http://httpstat.us/500" (BackendTask.Http.expectWhatever ()) + [ BackendTask.Http.get "http://localhost:1234/error-code/500" (BackendTask.Http.expectWhatever ()) |> BackendTask.mapError .recoverable |> test "http 500 error" (\result -> @@ -27,7 +27,7 @@ all = Ok () -> Expect.fail "Expected HTTP error, got Ok" ) - , BackendTask.Http.get "http://httpstat.us/404" (BackendTask.Http.expectWhatever ()) + , BackendTask.Http.get "http://localhost:1234/error-code/404" (BackendTask.Http.expectWhatever ()) |> BackendTask.mapError .recoverable |> test "http 404 error" (\result ->