Skip to content

refactor: api error handling#59

Open
olliethedev wants to merge 1 commit intomainfrom
feat/api-error-improvements
Open

refactor: api error handling#59
olliethedev wants to merge 1 commit intomainfrom
feat/api-error-improvements

Conversation

@olliethedev
Copy link
Collaborator

@olliethedev olliethedev commented Mar 5, 2026

Note

Medium Risk
Changes hook contracts and authorization/SSR loader control flow across multiple core plugins; while runtime shims still treat false as denial, TypeScript signatures and error propagation/messages may break consumer integrations.

Overview
Hook API breaking-direction refactor: Authorization and SSR loader hooks across ai-chat, blog, cms, form-builder, kanban, and ui-builder are changed from returning booleans to throwing errors to deny/cancel, with implementations updated to catch hook errors and surface them as appropriate HTTP errors (typically 403, 400 for rejected submissions) using the thrown message.

Compatibility + docs: Runtime “shim” handling still treats a returned false as denial for now, but TypeScript hook types/docs/examples are updated to the new throw-based pattern; the @btst/stack package version is bumped from 2.4.0 to 2.5.0.

Written by Cursor Bugbot for commit d445feb. This will update automatically on new commits. Configure here.

@vercel
Copy link

vercel bot commented Mar 5, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
better-stack-docs Ready Ready Preview, Comment Mar 5, 2026 0:06am

Request Review

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

query,
context,
)) as unknown;
if (result === false) shimDenied = true;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shim uses strict equality, weakening backward-compatible fail-safe

Medium Severity

The backward-compatibility shim checks result === false (strict equality), but the old code used !result (falsy check). This means an old-style hook that returns a falsy-but-not-false value (e.g. undefined from a forgotten return true) now silently allows access instead of denying it. The old !result pattern was fail-safe — any non-truthy return denied access. The new === false shim only catches explicit false, losing that safety net for existing consumers upgrading the library.

Additional Locations (2)

Fix in Cursor Fix in Web

if (shimDenied)
throw ctx.error(403, {
message: "Unauthorized: Cannot list posts",
});
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Identical shim pattern duplicated across sixty call sites

Medium Severity

The shimDenied backward-compatibility pattern (declare flag, try/catch the hook, check === false, re-throw as 403) is copy-pasted across 60+ call sites in blog, ai-chat, kanban, cms, form-builder, and ui-builder plugins. A small utility function (e.g. runHookWithShim) could replace all of them, reducing duplication and ensuring any fix to the shim logic (like the === false vs falsy-check issue) is applied in one place instead of sixty.

Additional Locations (2)

Fix in Cursor Fix in Web

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

Successfully merging this pull request may close these issues.

1 participant