mirror of
https://github.com/rowboatlabs/rowboat.git
synced 2026-04-29 02:24:02 +02:00
add debug logs for billing
This commit is contained in:
parent
a2a88f55c7
commit
eaa1c518d8
1 changed files with 5 additions and 1 deletions
|
|
@ -12,6 +12,8 @@ import { IProjectsRepository } from '@/src/application/repositories/projects.rep
|
|||
const BILLING_API_URL = process.env.BILLING_API_URL || 'http://billing';
|
||||
const BILLING_API_KEY = process.env.BILLING_API_KEY || 'test';
|
||||
|
||||
let logCounter = 1;
|
||||
|
||||
const GUEST_BILLING_CUSTOMER = {
|
||||
_id: "guest-user",
|
||||
userId: "guest-user",
|
||||
|
|
@ -136,7 +138,8 @@ export async function authorize(customerId: string, request: z.infer<typeof Auth
|
|||
}
|
||||
|
||||
export async function logUsage(customerId: string, request: z.infer<typeof LogUsageRequest>) {
|
||||
console.log(`logging billing usage for customer ${customerId}`, JSON.stringify(request));
|
||||
const reqId = logCounter++;
|
||||
console.log(`[${reqId}] logging billing usage for customer ${customerId} to ${BILLING_API_URL}`, reqId, JSON.stringify(request));
|
||||
const response = await fetch(`${BILLING_API_URL}/api/customers/${customerId}/log-usage`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
|
|
@ -145,6 +148,7 @@ export async function logUsage(customerId: string, request: z.infer<typeof LogUs
|
|||
},
|
||||
body: JSON.stringify(request)
|
||||
});
|
||||
console.log(`$[{reqId}] completed logging billing usage for customer ${customerId}`, reqId, response.status, response.statusText);
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to log usage: ${response.status} ${response.statusText} ${await response.text()}`);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue