@@ -140,10 +140,12 @@ export async function grantCreditOperation(params: {
140140
141141 // If the grant already exists, we can safely ignore this error since
142142 // the operation is idempotent - the grant was already created successfully
143- const isUniqueConstraintError = ( error : any ) : boolean => {
143+ const isUniqueConstraintError = ( error : unknown ) : boolean => {
144+ if ( typeof error !== 'object' || error === null ) return false
145+ const err = error as { code ?: string ; message ?: string }
144146 return (
145- error . code === '23505' ||
146- ( error . message && error . message . includes ( 'already exists' ) )
147+ err . code === '23505' ||
148+ ( err . message !== undefined && err . message . includes ( 'already exists' ) )
147149 )
148150 }
149151
@@ -190,7 +192,7 @@ export async function grantCreditOperation(params: {
190192 expires_at : expiresAt ,
191193 created_at : now ,
192194 } )
193- } catch ( error : any ) {
195+ } catch ( error : unknown ) {
194196 if ( isUniqueConstraintError ( error ) ) {
195197 logger . info (
196198 { userId, operationId, type, amount } ,
@@ -215,7 +217,7 @@ export async function grantCreditOperation(params: {
215217 expires_at : expiresAt ,
216218 created_at : now ,
217219 } )
218- } catch ( error : any ) {
220+ } catch ( error : unknown ) {
219221 if ( isUniqueConstraintError ( error ) ) {
220222 logger . info (
221223 { userId, operationId, type, amount } ,
@@ -272,10 +274,11 @@ export async function processAndGrantCredit(params: {
272274 )
273275 } ,
274276 } )
275- } catch ( error : any ) {
277+ } catch ( error : unknown ) {
278+ const errorMessage = error instanceof Error ? error . message : 'Unknown error'
276279 await logSyncFailure ( {
277280 id : operationId ,
278- errorMessage : error . message ,
281+ errorMessage,
279282 provider : 'internal' ,
280283 logger,
281284 } )
0 commit comments