Use local artificial error API to avoid rate limit.

This commit is contained in:
Dillon Kearns 2023-02-06 09:52:59 -08:00
parent c24d93d705
commit ad3d68cc9b
2 changed files with 19 additions and 2 deletions

View File

@ -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

View File

@ -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 ->