refactor: apply new utilities and constants across codebase
P0 fixes: - KV Cache migration: security.ts now delegates to kv-cache.ts (74% code reduction) - Environment validation: index.ts validates env on first request - Type safety: optimistic-lock.ts removes `as any` with proper interface P1 improvements: - Constants applied to deposit-agent.ts (TRANSACTION_STATUS, TRANSACTION_TYPE) - Constants applied to callback-handler.ts (CALLBACK_PREFIXES) - Constants applied to domain-tool.ts (MESSAGE_MARKERS) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -32,6 +32,13 @@ import { createLogger } from './logger';
|
||||
|
||||
const logger = createLogger('optimistic-lock');
|
||||
|
||||
/**
|
||||
* Type guard for Error with captureStackTrace method
|
||||
*/
|
||||
interface ErrorWithCapture {
|
||||
captureStackTrace?: (target: object, constructor?: Function) => void;
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom error for optimistic lock failures
|
||||
*/
|
||||
@@ -40,10 +47,9 @@ export class OptimisticLockError extends Error {
|
||||
super(message);
|
||||
this.name = 'OptimisticLockError';
|
||||
// Maintain proper stack trace for debugging (Node.js only, not available in Workers)
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
if (typeof (Error as any).captureStackTrace === 'function') {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
(Error as any).captureStackTrace(this, OptimisticLockError);
|
||||
const ErrorConstructor = Error as unknown as ErrorWithCapture;
|
||||
if (typeof ErrorConstructor.captureStackTrace === 'function') {
|
||||
ErrorConstructor.captureStackTrace(this, OptimisticLockError);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user