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

4xx and 5xx response missing body and text #11

Closed
ngot opened this issue Jul 5, 2020 · 4 comments
Closed

4xx and 5xx response missing body and text #11

ngot opened this issue Jul 5, 2020 · 4 comments
Assignees
Labels
invalid This doesn't seem right

Comments

@ngot
Copy link

ngot commented Jul 5, 2020

Issue

Setup:

  • deno 1.0.5
  • v8 8.4.300
  • typescript 3.9.2

When server response 4xx or 5xx, superdeno's response doesn't have body or text, so there is no way to test the HTTP body part.

import {
  Application,
} from "https://deno.land/x/ako/mod.ts";
import { superdeno } from "https://deno.land/x/[email protected]/mod.ts";
import { describe, it } from "https://deno.land/x/[email protected]/test/utils.ts";

describe("ctx.onerror(err)", () => {
  it("should respond", async () => {
    const app = new Application();

    app.use((ctx, next) => {
      ctx.body = "something else";

      ctx.throw(418, "boom");
    });

    const res = await superdeno(app.listen())
      .head("/")
      .expect(418)
      .expect("Content-Length", "4")
      .expect("Content-Type", "text/plain; charset=utf-8");
    console.log(res);

    // res.body is null
    // res.text is null
  });
});

curl:

curl -i  127.0.0.1:5000
HTTP/1.1 418 I'm a teapot
content-length: 4
content-type: text/plain; charset=utf-8

boom% 
@ngot
Copy link
Author

ngot commented Jul 5, 2020

Read #1 again, realized that patch only fixed the error throw, not the empty body.

@asos-craigmorten
Copy link
Collaborator

Hi @ngot I've added a test for this for both Oak and Ako in 1.6.0.

I believe the issue is that in the sample test you are making a HEAD request which will discard the body, whereas in your curl request you are implicitly using a GET request, so the body is returned.

Test added here: https://github.com/asos-craigmorten/superdeno/blob/main/test/supertest.ako.test.ts#L7 and passing in CICD.

@asos-craigmorten asos-craigmorten added invalid This doesn't seem right and removed needs investigation labels Jul 6, 2020
@ngot
Copy link
Author

ngot commented Jul 7, 2020

@asos-craigmorten Thanks for the investigation. That's right, I didn't realise I was using the HEAD request. I was definitely too blind to find that.

@asos-craigmorten
Copy link
Collaborator

No worries - thanks for raising anyway! Lead to some extra tests and a small refactor so all good 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

2 participants