winglang / wing

A programming language for the cloud ☁️ A unified programming model, combining infrastructure and runtime code into one language ⚡
https://winglang.io
Other
5.07k stars 198 forks source link

tf-aws api gateway 404 handler header issues #4091

Open skorfmann opened 1 year ago

skorfmann commented 1 year ago

I tried this:

bring cloud;
bring http;

let api = new cloud.Api();

api.get("/hello", inflight (req) => {
  return {
    status: 200,
    body: "world"
  };
});

test "it responds with 404 when adding a header" {
    let url = "{api.url}/does-not-exists";
    let response = http.post(url, {
      headers: {
        "Content-Type": "text/plain",  // this is the important part 
      }
    });

    assert(response.status == 404);
    assert(response.body?.contains("Error") == true);
}

playground

run wing test -t tf-aws

This happened:

it'll return a 500 error.

fail ┌ 404.tfaws » root/Test.fzBvIV7IWC/env1/test:it responds with 404 when adding a header
     │ Error: Invoke failed with message: "Unhandled". Full error: "{"errorType":"Error","errorMessage":"assertion failed: response.status == 404","trace":["Error: assertion failed: response.status == 404","    at /var/task/index.js:21:23","    at $Closure3.handle (/var/task/index.js:22:15)","    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)","    at async exports.handler (/var/task/index.js:5414:10)"]}"
     │     at FunctionClient.invokeWithLogs (/Users/sebastian/projects/wing-cloud/wing/libs/wingsdk/lib/shared-aws/function.inflight.js:50:19)
     │     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
     │     at async TestRunnerClient.runTest (/Users/sebastian/projects/wing-cloud/wing/libs/wingsdk/lib/shared-aws/test-runner.inflight.js:28:41)
     │     at async /Users/sebastian/projects/wing-cloud/wing/apps/wing/dist/commands/test.js:314:30
     │     at async withSpinner (/Users/sebastian/projects/wing-cloud/wing/apps/wing/dist/util.js:55:24)
     │     at async testTfAws (/Users/sebastian/projects/wing-cloud/wing/apps/wing/dist/commands/test.js:311:25)
     │     at async testOne (/Users/sebastian/projects/wing-cloud/wing/apps/wing/dist/commands/test.js:127:20)
     │     at async testFile (/Users/sebastian/projects/wing-cloud/wing/apps/wing/dist/commands/test.js:55:39)
     │     at async Promise.all (index 0)
     │     at async Object.test (/Users/sebastian/projects/wing-cloud/wing/apps/wing/dist/commands/test.js:66:5)
     └     at async Command.<anonymous> (/Users/sebastian/projects/wing-cloud/wing/apps/wing/dist/cli.js:46:30)

Api Gateway logs:

Mon Sep 04 19:40:28 UTC 2023 : Execution failed due to configuration error: Unable to parse statusCode. It should be an integer that is defined in the request template.
Mon Sep 04 19:40:28 UTC 2023 : Method completed with status: 500

Essentially, there would have to be a wildcard matcher for the mock request template mapping, haven't found a way to do it.

It works as expected when the Content-Type header is not specified.

I expected this:

it returns 404 even when Content-Type header is specified with something else than application/json.

Is there a workaround?

No response

Component

SDK

Wing Version

v0.29

Node.js Version

18.6.0

Platform(s)

MacOS

Anything else?

No response

Community Notes

staycoolcall911 commented 1 year ago

Instead of tackling this issue, it might be worthwhile to do #4097 since it may fix this issue as well We decided not to follow through with #4097

github-actions[bot] commented 1 year ago

Hi,

This issue hasn't seen activity in 60 days. Therefore, we are marking this issue as stale for now. It will be closed after 7 days. Feel free to re-open this issue when there's an update or relevant information to be added. Thanks!

github-actions[bot] commented 9 months ago

Hi,

This issue hasn't seen activity in 60 days. Therefore, we are marking this issue as stale for now. It will be closed after 7 days. Feel free to re-open this issue when there's an update or relevant information to be added. Thanks!

staycoolcall911 commented 9 months ago

Still fails

github-actions[bot] commented 6 months ago

Hi,

This issue hasn't seen activity in 90 days. Therefore, we are marking this issue as stale for now. It will be closed after 7 days. Feel free to re-open this issue when there's an update or relevant information to be added. Thanks!

staycoolcall911 commented 6 months ago

Still fails

github-actions[bot] commented 2 months ago

Hi,

This issue hasn't seen activity in 90 days. Therefore, we are marking this issue as stale for now. It will be closed after 7 days. Feel free to re-open this issue when there's an update or relevant information to be added. Thanks!