Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generating empty json object eventough the output error type is Unit #3258

Open
jiramares opened this issue Dec 17, 2024 · 1 comment
Open
Labels
bug Something isn't working

Comments

@jiramares
Copy link

Describe the bug
When the outError type is Unit the response should be empty.

To Reproduce

val ep = Endpoint(RoutePattern.GET / "greeting" / PathCodec.string("name") / "exclamation" / PathCodec.string("bool"))
    .outCodec(HttpCodec.content[Greeting](MediaType.text.plain))
    .outError[Unit](Status.NotFound)
    .implement(greetingHandler)

generates response:

curl -v http://localhost:8080/greeting/Jane/exclamation/o
* Host localhost:8080 was resolved.
* IPv6: ::1
* IPv4: 127.0.0.1
*   Trying [::1]:8080...
* Connected to localhost (::1) port 8080
> GET /greeting/Jane/exclamation/o HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/8.5.0
> Accept: */*
> 
< HTTP/1.1 404 Not Found
< content-type: application/json
< date: Mon, 16 Dec 2024 15:04:26 GMT
< content-length: 2
< 
* Connection #0 to host localhost left intact
{}

Expected behaviour
Send back empty response (no content-type??) and no data

curl -v http://localhost:8080/greeting/Jane/exclamation/o
* Host localhost:8080 was resolved.
* IPv6: ::1
* IPv4: 127.0.0.1
*   Trying [::1]:8080...
* Connected to localhost (::1) port 8080
> GET /greeting/Jane/exclamation/o HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/8.5.0
> Accept: */*
> 
< HTTP/1.1 404 Not Found
< date: Mon, 16 Dec 2024 15:04:26 GMT
< content-length: 2
< 
* Connection #0 to host localhost left intact

Dependencies

    "dev.zio" %% "zio" % "2.1.9",
    "dev.zio" %% "zio-http" % "3.0.1"
    "dev.zio" %% "zio-schema" % "1.4.1"
@jiramares jiramares added the bug Something isn't working label Dec 17, 2024
@jiramares
Copy link
Author

Tested with text/plain response content type:

val ep3 = Endpoint(RoutePattern.GET / "greeting" / PathCodec.string("name") / "exclamation" / PathCodec.string("bool"))
    .outCodec(HttpCodec.content[Greeting](MediaType.text.plain))
    .copy(error = HttpCodec.content[Unit](MediaType.text.plain) ++ HttpCodec.status(Status.NotFound))
    .implement(greetingHandler)

and behaviour is stilll strange:

curl -v http://localhost:8080/greeting/Jane/exclamation/n
* Host localhost:8080 was resolved.
* IPv6: ::1
* IPv4: 127.0.0.1
*   Trying [::1]:8080...
* Connected to localhost (::1) port 8080
> GET /greeting/Jane/exclamation/n HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/8.5.0
> Accept: */*
> 
< HTTP/1.1 404 Not Found
< content-type: text/plain
< date: Tue, 17 Dec 2024 10:22:35 GMT
< content-length: 2
< 
* Connection #0 to host localhost left intact
()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant