Skip to content
This repository was archived by the owner on Feb 6, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion bin/auth-api/src/lib/lago.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,28 @@ const client = Client(process.env.LAGO_API_KEY as string, {
baseUrl: "https://api.getlago.com/api/v1",
});

// Helper to extract error details from Lago responses
function extractLagoError(error: unknown): Record<string, unknown> {
if (error instanceof Error) {
return { error: error.message };
}
// Lago client returns Response objects with ok, status, and data properties
if (error && typeof error === 'object') {
const resp = error as { ok?: boolean; status?: number; data?: unknown; statusText?: string };
if ('status' in resp) {
const result: Record<string, unknown> = {
error: resp.statusText || `HTTP ${resp.status}`,
status: resp.status,
};
if (resp.data) {
result.details = resp.data;
}
return result;
}
}
return { error: String(error) };
}

// Helper to wrap Lago calls with timing
async function timedLagoCall<T>(operation: string, fn: () => Promise<T>): Promise<T> {
const start = Date.now();
Expand All @@ -23,14 +45,15 @@ async function timedLagoCall<T>(operation: string, fn: () => Promise<T>): Promis
return result;
} catch (error) {
const duration_ms = Date.now() - start;
const errorInfo = extractLagoError(error);
console.log(JSON.stringify({
timestamp: new Date().toISOString(),
level: "error",
type: "lago",
operation,
duration_ms,
...(duration_ms > 5000 && { slowCall: true }),
error: error instanceof Error ? error.message : String(error),
...errorInfo,
}));
throw error;
}
Expand Down
1 change: 1 addition & 0 deletions bin/auth-api/src/services/auth0.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ auth0Api.interceptors.response.use(
...(duration_ms && duration_ms > 5000 && { slowCall: true }),
error_code: error.code,
error_message: error.message,
...(error.response?.data && { response_body: error.response.data }),
}));
throw error;
},
Expand Down