Add debug logging to PB requests
This commit is contained in:
parent
4cb5848098
commit
1df769777a
1 changed files with 10 additions and 4 deletions
|
|
@ -19,18 +19,24 @@ function generateVisitorHash(ip: string, userAgent: string): string {
|
||||||
|
|
||||||
async function pbRequest(method: string, path: string, body?: object) {
|
async function pbRequest(method: string, path: string, body?: object) {
|
||||||
const url = `${POCKETBASE_URL}${path}`;
|
const url = `${POCKETBASE_URL}${path}`;
|
||||||
|
console.log('[Increment Views] PB Request:', method, url);
|
||||||
const options: RequestInit = {
|
const options: RequestInit = {
|
||||||
method,
|
method,
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
};
|
};
|
||||||
if (body) options.body = JSON.stringify(body);
|
if (body) {
|
||||||
|
options.body = JSON.stringify(body);
|
||||||
|
console.log('[Increment Views] PB Body:', JSON.stringify(body));
|
||||||
|
}
|
||||||
|
|
||||||
const res = await fetch(url, options);
|
const res = await fetch(url, options);
|
||||||
if (!res.ok) {
|
const status = res.status;
|
||||||
const err = await res.text();
|
const err = await res.text();
|
||||||
throw new Error(`PB ${method} ${path}: ${res.status} - ${err}`);
|
console.log('[Increment Views] PB Response:', status, err);
|
||||||
|
if (!res.ok) {
|
||||||
|
throw new Error(`PB ${method} ${path}: ${status} - ${err}`);
|
||||||
}
|
}
|
||||||
return res.json();
|
return JSON.parse(err) || {};
|
||||||
}
|
}
|
||||||
|
|
||||||
export const POST: APIRoute = async ({ request, url }) => {
|
export const POST: APIRoute = async ({ request, url }) => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue