Skip to content

Commit 5078747

Browse files
committed
Enhance error handling and API response for documentation tools
- Introduced error capturing for failed HTTP requests in the docs tools API, improving debugging capabilities. - Updated the API response for unsupported methods to include an 'Allow' header, clarifying the expected request type. These changes enhance the robustness of the documentation tools integration and improve developer experience.
1 parent 30d53e8 commit 5078747

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

  • apps/backend/src/lib/ai/tools
  • docs/src/app/api/internal/docs-tools

apps/backend/src/lib/ai/tools/docs.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { tool } from "ai";
22
import { getEnvVariable, getNodeEnvironment } from "@stackframe/stack-shared/dist/utils/env";
3+
import { captureError } from "@stackframe/stack-shared/dist/utils/errors";
34
import { z } from "zod";
45

56
type DocsToolHttpResult = {
@@ -22,11 +23,9 @@ function getDocsToolsBaseUrl(): string {
2223
async function postDocsToolAction(action: Record<string, unknown>): Promise<string> {
2324
const base = getDocsToolsBaseUrl();
2425
const secret = getEnvVariable("STACK_INTERNAL_DOCS_TOOLS_SECRET", "");
25-
const headers: Record<string, string> = {
26-
"Content-Type": "application/json",
27-
};
26+
const headers = new Headers({ "Content-Type": "application/json" });
2827
if (secret !== "") {
29-
headers["x-stack-internal-docs-tools-secret"] = secret;
28+
headers.set("x-stack-internal-docs-tools-secret", secret);
3029
}
3130

3231
const res = await fetch(`${base}/api/internal/docs-tools`, {
@@ -37,6 +36,7 @@ async function postDocsToolAction(action: Record<string, unknown>): Promise<stri
3736

3837
if (!res.ok) {
3938
const errBody = await res.text();
39+
captureError("docs-tools-http-error", new Error(`Stack Auth docs tools error (${res.status}): ${errBody}`));
4040
return `Stack Auth docs tools error (${res.status}): ${errBody}`;
4141
}
4242

docs/src/app/api/internal/docs-tools/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,6 @@ export async function POST(req: NextRequest) {
5050
export async function GET() {
5151
return NextResponse.json(
5252
{ error: "Use POST with a DocsToolAction body" },
53-
{ status: 405 },
53+
{ status: 405, headers: { Allow: "POST" } },
5454
);
5555
}

0 commit comments

Comments
 (0)