mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-23 17:07:42 +00:00
refactor(ai-usage): use Prisma.PrismaClientKnownRequestError for P2002 handling
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { prisma } from '@shumai/db'
|
||||
import { prisma, Prisma } from '@shumai/db'
|
||||
import type { TeamUsageStatsResponse, Timeframe } from '@shumai/dtos'
|
||||
import { HTTPException } from 'hono/http-exception'
|
||||
|
||||
@@ -92,13 +92,8 @@ export class AiUsageService {
|
||||
cost: params.cost,
|
||||
},
|
||||
})
|
||||
} catch (err: unknown) {
|
||||
if (
|
||||
err &&
|
||||
typeof err === 'object' &&
|
||||
'code' in err &&
|
||||
(err as { code: string }).code === 'P2002'
|
||||
) {
|
||||
} catch (err) {
|
||||
if (err instanceof Prisma.PrismaClientKnownRequestError && err.code === 'P2002') {
|
||||
await prisma.aiUsage.updateMany({
|
||||
where: {
|
||||
teamId: params.teamId,
|
||||
|
||||
Reference in New Issue
Block a user