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

Throwing an error while HTTP streaming is enabled causes response to never be sent #324

Open
nimobeeren opened this issue Jan 8, 2025 · 1 comment

Comments

@nimobeeren
Copy link

Description

When HTTP streaming is enabled with app.setup({ enableHttpStream: true }), throwing any error causes the the response to never be sent and never logging anything.

Expected behavior

Throwing an error causes a response with status 500 to be sent and the error to be logged, same as when HTTP streaming is disabled.

Reproduction

import {
  app,
  type HttpRequest,
  type InvocationContext,
  type HttpResponseInit,
} from "@azure/functions";

app.setup({ enableHttpStream: true });

app.http("proxy", {
  methods: ["POST"],
  handler: proxy,
});

export async function proxy(
  request: HttpRequest,
  context: InvocationContext
): Promise<HttpResponseInit> {
  throw new Error("Kaboom! 💣");
}

Setting enableHttpStream: false results in the expected behavior, but then streaming won't work.

@nimobeeren
Copy link
Author

nimobeeren commented Jan 8, 2025

As a workaround, I'm wrapping my main handler in a try/catch. But this should be handled by the library IMO.

app.http("proxy", {
  methods: ["POST"],
  handler: safeProxy,
});

export async function safeProxy(
  request: HttpRequest,
  context: InvocationContext
): Promise<HttpResponseInit> {
  try {
    return await proxy(request, context);
  } catch (error) {
    context.error(error);
    return { status: 500 };
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant