Skip to content

Commit 502040a

Browse files
committed
pass in logger to logSyncFailure
1 parent 2f533a5 commit 502040a

File tree

4 files changed

+36
-9
lines changed

4 files changed

+36
-9
lines changed

backend/src/llm-apis/message-cost-tracker.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,12 @@ async function syncMessageToStripe(messageData: {
301301
{ ...logContext, error: errorMessage },
302302
'Failed to sync usage to Stripe after retries.',
303303
)
304-
await logSyncFailure(messageId, errorMessage, 'stripe')
304+
await logSyncFailure({
305+
id: messageId,
306+
errorMessage,
307+
provider: 'stripe',
308+
logger,
309+
})
305310
}
306311
}
307312

common/src/util/sync-failure.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
import { sql } from 'drizzle-orm'
22

33
import db from '../db'
4-
import { logger } from './logger'
54
import * as schema from '../db/schema'
65

7-
export async function logSyncFailure(
8-
id: string,
9-
errorMessage: string,
6+
import type { Logger } from '@codebuff/types/logger'
7+
8+
export async function logSyncFailure({
9+
id,
10+
errorMessage,
1011
provider = 'stripe',
11-
): Promise<void> {
12+
logger,
13+
}: {
14+
id: string
15+
errorMessage: string
16+
provider: string
17+
logger: Logger
18+
}): Promise<void> {
1219
try {
1320
await db
1421
.insert(schema.syncFailure)

packages/billing/src/grant-credits.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,12 @@ export async function processAndGrantCredit(
259259
},
260260
)
261261
} catch (error: any) {
262-
await logSyncFailure(operationId, error.message, 'internal')
262+
await logSyncFailure({
263+
id: operationId,
264+
errorMessage: error.message,
265+
provider: 'internal',
266+
logger,
267+
})
263268
logger.error(
264269
{ operationId, error },
265270
'processAndGrantCredit failed after retries, logged to sync_failure',

web/src/app/api/auth/[...nextauth]/auth-options.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,12 @@ async function createAndLinkStripeCustomer(
6767
{ userId, error },
6868
'Failed to create Stripe customer or update user record.'
6969
)
70-
await logSyncFailure(userId, errorMessage)
70+
await logSyncFailure({
71+
id: userId,
72+
errorMessage,
73+
provider: 'stripe',
74+
logger,
75+
})
7176
return null
7277
}
7378
}
@@ -107,7 +112,12 @@ async function createInitialCreditGrant(
107112
{ userId, error: grantError },
108113
'Failed to create initial credit grant.'
109114
)
110-
await logSyncFailure(userId, errorMessage)
115+
await logSyncFailure({
116+
id: userId,
117+
errorMessage,
118+
provider: 'stripe',
119+
logger,
120+
})
111121
}
112122
}
113123

0 commit comments

Comments
 (0)