fix(attachment-counts api): surface real error details instead of generic PB admin message

capture the thrown error, extract its message if available, and append it to the base "PB admin unavailable" error response. fall back to a generic unknown error message for non-Error failures, revealing actionable debugging details like missing env vars or invalid PB credentials.
This commit is contained in:
SJCoetz 2026-07-03 22:52:39 +02:00
parent 05abe499b0
commit 235c0ad39b

View file

@ -42,9 +42,14 @@ export async function GET(req: NextRequest) {
let adminPb;
try {
adminPb = await getAdminPocketBase();
} catch {
} catch (err) {
// Surface the real reason — the generic "PB admin unavailable"
// message was hiding the actual cause (missing env var, wrong
// password, PB unreachable from the prod container, etc.).
const reason =
err instanceof Error ? err.message : "unknown admin error";
return NextResponse.json(
{ error: "PB admin unavailable" },
{ error: `PB admin unavailable: ${reason}` },
{ status: 500 },
);
}