Skip to content

Incorrectly resolve http client response status code #74

@lost22git

Description

@lost22git

code

app [Model, server] { pf: platform "https://github.com/roc-lang/basic-webserver/releases/download/0.9.0/taU2jQuBf-wB8EJb0hAkrYLYOGacUU5Y9reiHG45IY4.tar.br" }

import pf.Stdout
import pf.Http exposing [Request, Response]
import pf.Url

Model : {}

server = { init: Task.ok {}, respond }

respond : Request, Model -> Task Response [ServerErr Str]_
respond = \req, _ -> apiProxy req |> Task.mapErr handleErr

AppError : [
    ParamNotFound Str,
    HttpErr Http.Err,
    StdoutErr Stdout.Err,
]

handleErr : AppError -> [ServerErr Str]
handleErr = \e -> ServerErr (Inspect.toStr e)

apiProxy : Request -> Task Response AppError
apiProxy = \req ->
    target =
        req.url
            |> Url.fromStr
            |> Url.queryParams
            |> Dict.get "target"
            |> Task.fromResult
            |> Task.mapErr! \_ -> ParamNotFound "target"

    Stdout.line! "Fetching [$(Http.methodToStr req.method)] $(target)"

    targetRes = { req & url: target, timeout: NoTimeout } |> Http.send!
    dbg targetRes

    Task.ok targetRes

http test report

❯ xh get http://localhost:8000/proxy?target=https://httpbin.org/ip
HTTP/1.1 500 Internal Server Error
Content-Length: 15
Date: Sat, 21 Sep 2024 13:23:03 GMT

Panic detected!

server error report

❯ roc dev proxy_server.roc --linker=legacy
Listening on <http://127.0.0.1:8000>
Fetching [Get] https://httpbin.org/ip
[proxy_server.roc:36] {body: [123, 10, 32, 32, 34, 111, 114, ...], headers: [{name: "date", value: "Sat, 21 Sep 2024 13:23:03 GMT"}, {name: "content-type", value: "application/json"}, {name: "content-length", value: "33"}, {name: "server", value: "gunicorn/19.9.0"}, {name: "access-control-allow-origin", value: "*"}, {name: "access-control-allow-credentials", value: "true"}], status: 0}
thread 'tokio-runtime-worker' panicked at crates/roc_host/src/http_server.rs:91:13:
not yet implemented: invalid status code from Roc: 0
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread 'tokio-runtime-worker' panicked at crates/roc_host/src/http_server.rs:112:26:
called `Result::unwrap()` on an `Err` value: JoinError::Panic(Id(18), ...)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions