mirror of
https://github.com/bitbaum/orangecat.git
synced 2026-12-04 19:07:35 +01:00
diag(entities): surface why STATUS endpoint returns 404
Probed /api/entities/{entityType}/{id}/status PATCH end-to-end after
the wishlist privacy fix and found the endpoint silently 404s for
EVERY actor-owned entity tested (project, wishlist). It's been
returning the same opaque "not found" since cfd98d60. Users who
click Publish Now in the EntityCreationSuccess UI get a toast
"Failed to publish" with no signal about why — could be missing row,
could be RLS-blocked read, could be a bug in this route. The
endpoint's `.single()` collapses all three into PGRST116.
This commit doesn't fix the underlying 404 — root cause is still
under investigation and likely lives in either the RLS policies
(projects.user_id reference is suspicious despite being populated,
wishlists owner read works via /api/wishlists/{id} but not here) or
in this route's auth context propagation. What this commit DOES is
make the failure mode legible:
- Switch from .single() to .maybeSingle() so a non-existent row
returns null cleanly instead of throwing an error that masks
whether RLS-blocked vs missing.
- Log fetchError details (code, message, details) on the error
branch so the actual PostgREST error surfaces in vercel logs.
- Log the "row not visible" branch separately with a note that it
could be RLS-blocked OR row-missing — next time a user reports a
Publish Now failure we can tell which.
The behavior is unchanged for callers (still returns 404). What
changes is that operators can now see, in logs, why. The actual
root-cause fix needs the diagnostics to land first so the next
person debugging this has something to grep for.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
c9897f9acb
commit
410e8439c8
1 file changed
+25
-2
@@ -93,9 +93,32 @@ export const PATCH = withAuth(async (request: AuthenticatedRequest, context: Rou
|
||||
const { data: existing, error: fetchError } = await (supabase.from(tableName) as any)
|
||||
.select(`id, ${statusSelectColumn}, ${userIdField}`)
|
||||
.eq('id', id)
|
||||
.single();
|
||||
.maybeSingle();
|
||||
|
||||
if (fetchError || !existing) {
|
||||
if (fetchError) {
|
||||
// PostgREST + supabase-js collapses RLS-blocked-read into a generic
|
||||
// 404-shaped error if we use `.single()`, hiding the actual failure
|
||||
// mode. Surface the error code/details so this stops being invisible.
|
||||
logger.error('Entity status: fetch failed', {
|
||||
entityType,
|
||||
id,
|
||||
userId: user.id,
|
||||
errorCode: fetchError.code,
|
||||
errorMessage: fetchError.message,
|
||||
errorDetails: fetchError.details,
|
||||
});
|
||||
return apiNotFound(`${entityType} not found`);
|
||||
}
|
||||
if (!existing) {
|
||||
// .maybeSingle returns null both for "row doesn't exist" AND "RLS
|
||||
// blocked the read." Log so we can tell them apart when a user reports
|
||||
// a Publish Now toast — historically these silently degraded to 404.
|
||||
logger.warn('Entity status: row not visible to user', {
|
||||
entityType,
|
||||
id,
|
||||
userId: user.id,
|
||||
likelyCause: 'RLS-blocked or row missing',
|
||||
});
|
||||
return apiNotFound(`${entityType} not found`);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user