Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
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.
  • Loading branch information
mantrakp04 committed Mar 24, 2026
commit 50787475a29f3941843bd9d774d8909fa9694c43
8 changes: 4 additions & 4 deletions apps/backend/src/lib/ai/tools/docs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { tool } from "ai";
import { getEnvVariable, getNodeEnvironment } from "@stackframe/stack-shared/dist/utils/env";
import { captureError } from "@stackframe/stack-shared/dist/utils/errors";
import { z } from "zod";

type DocsToolHttpResult = {
Expand All @@ -22,11 +23,9 @@ function getDocsToolsBaseUrl(): string {
async function postDocsToolAction(action: Record<string, unknown>): Promise<string> {
const base = getDocsToolsBaseUrl();
const secret = getEnvVariable("STACK_INTERNAL_DOCS_TOOLS_SECRET", "");
const headers: Record<string, string> = {
"Content-Type": "application/json",
};
const headers = new Headers({ "Content-Type": "application/json" });
if (secret !== "") {
headers["x-stack-internal-docs-tools-secret"] = secret;
headers.set("x-stack-internal-docs-tools-secret", secret);
}

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

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

Expand Down
2 changes: 1 addition & 1 deletion docs/src/app/api/internal/docs-tools/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@ export async function POST(req: NextRequest) {
export async function GET() {
return NextResponse.json(
{ error: "Use POST with a DocsToolAction body" },
{ status: 405 },
{ status: 405, headers: { Allow: "POST" } },
);
Comment thread
mantrakp04 marked this conversation as resolved.
}
Loading