MCPcopy Create free account
hub / github.com/Noumena-Network/code / checkMockFastModeRateLimit

Function checkMockFastModeRateLimit

src/services/mockRateLimits.ts:848–883  ·  view source on GitHub ↗
(
  isFastModeActive?: boolean,
)

Source from the content-addressed store, hash-verified

846}
847
848export function checkMockFastModeRateLimit(
849 isFastModeActive?: boolean,
850): MockHeaders | null {
851 if (mockFastModeRateLimitDurationMs === null) {
852 return null
853 }
854
855 // Only throw when fast mode is active
856 if (!isFastModeActive) {
857 return null
858 }
859
860 // Check if the rate limit has expired
861 if (
862 mockFastModeRateLimitExpiresAt !== null &&
863 Date.now() >= mockFastModeRateLimitExpiresAt
864 ) {
865 clearMockHeaders()
866 return null
867 }
868
869 // Set expiry on first error (not when scenario is configured)
870 if (mockFastModeRateLimitExpiresAt === null) {
871 mockFastModeRateLimitExpiresAt =
872 Date.now() + mockFastModeRateLimitDurationMs
873 }
874
875 // Compute dynamic retry-after based on remaining time
876 const remainingMs = mockFastModeRateLimitExpiresAt - Date.now()
877 const headersToSend = { ...mockHeaders }
878 headersToSend['retry-after'] = String(
879 Math.max(1, Math.ceil(remainingMs / 1000)),
880 )
881
882 return headersToSend
883}

Callers 1

checkMockRateLimitErrorFunction · 0.85

Calls 2

clearMockHeadersFunction · 0.85
maxMethod · 0.80

Tested by

no test coverage detected