We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
runtime error: There is already a Construct with name '$Closure1'
bring cloud; struct JsonApiProps { api: cloud.Api; } struct JsonApiResponse { status: num?; headers: Map<str>?; body: Json?; } pub class JsonApi { api: cloud.Api; pub url: str; new(props: JsonApiProps) { this.api = props.api; this.url = this.api.url; } wrapHandler(handler: inflight (cloud.ApiRequest): JsonApiResponse): inflight (cloud.ApiRequest): cloud.ApiResponse { return inflight (request: cloud.ApiRequest): cloud.ApiResponse => { try { let response = handler(request); let headers = response.headers?.copyMut(); headers?.set("content-type", "application/json"); let var bodyStr = ""; if let body = response.body { bodyStr = Json.stringify(body); } return { status: response.status ?? 200, headers: headers?.copy(), body: bodyStr, }; } catch error { // TODO: This is a hack to get around the fact that errors are just strings if error == "Bad credentials" { return { status: 401, headers: { "content-type": "application/json", }, body: Json.stringify({ error: error, }), }; } return { status: 500, headers: { "content-type": "application/json", }, body: Json.stringify({ error: error, }), }; } }; } pub get(path: str, handler: inflight (cloud.ApiRequest): JsonApiResponse) { this.api.get(path, this.wrapHandler(handler)); } } let jsonApi = new JsonApi(api: new cloud.Api()); jsonApi.get("/a", inflight () => { return { body: { path: "/a"}, }; }); jsonApi.get("/b", inflight () => { return { body: { path: "/b"}, }; });
runtime error: There is already a Construct with name '$Closure1' in JsonApi [JsonApi]
After #4993 got merged, I'd assume that we wouldn't get this error again.
Yes, doing an internal counter for preflights:
bring cloud; struct JsonApiProps { api: cloud.Api; } struct JsonApiResponse { status: num?; headers: Map<str>?; body: Json?; } pub class JsonApi { api: cloud.Api; pub url: str; var handlerCount: num; new(props: JsonApiProps) { this.api = props.api; this.url = this.api.url; this.handlerCount = 0; } wrapHandler(handler: inflight (cloud.ApiRequest): JsonApiResponse): inflight (cloud.ApiRequest): cloud.ApiResponse { class MyHandler { inflight handle(request: cloud.ApiRequest): cloud.ApiResponse { try { let response = handler(request); let headers = response.headers?.copyMut(); headers?.set("content-type", "application/json"); let var bodyStr = ""; if let body = response.body { bodyStr = Json.stringify(body); } return { status: response.status ?? 200, headers: headers?.copy(), body: bodyStr, }; } catch error { // TODO: This is a hack to get around the fact that errors are just strings if error == "Bad credentials" { return { status: 401, headers: { "content-type": "application/json", }, body: Json.stringify({ error: error, }), }; } return { status: 500, headers: { "content-type": "application/json", }, body: Json.stringify({ error: error, }), }; } } } this.handlerCount += 1; return new MyHandler() as "Handler{this.handlerCount}"; } pub get(path: str, handler: inflight (cloud.ApiRequest): JsonApiResponse) { this.api.get(path, this.wrapHandler(handler)); } }
No response
0.50.6
The text was updated successfully, but these errors were encountered:
here's another example of where this is troublesome simulator - essentially adding inflight functions programmatically is broken.
would be really nice if there was a proper solution to this
Sorry, something went wrong.
Duplicates #4925
No branches or pull requests
I tried this:
This happened:
runtime error: There is already a Construct with name '$Closure1' in JsonApi [JsonApi]
I expected this:
After #4993 got merged, I'd assume that we wouldn't get this error again.
Is there a workaround?
Yes, doing an internal counter for preflights:
Anything else?
No response
Wing Version
0.50.6
Node.js Version
No response
Platform(s)
No response
Community Notes
The text was updated successfully, but these errors were encountered: