Skip to content

Commit ac7faaa

Browse files
authored
fix/usage error (#12)
1 parent eb7c81f commit ac7faaa

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

src/relay/index.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -128,24 +128,17 @@ exports.handler = async (event, context) => {
128128
return await createResponse(401, { error: 'Invalid API key' });
129129
}
130130

131-
// Check daily limit BEFORE processing request
131+
// Always check usage status for headers and quota info
132132
usageStatus = await checkDailyLimit(user.userId, user.tier);
133-
if (usageStatus.exceeded) {
134-
return await createResponse(429, {
135-
error: 'Daily request limit exceeded',
136-
dailyLimit: usageStatus.dailyLimit,
137-
currentUsage: usageStatus.currentUsage,
138-
resetTime: 'midnight UTC'
139-
}, user, usageStatus);
140-
}
141133
}
142134

135+
// Handle quota information requests BEFORE rate limiting check
143136
if (event.httpMethod === 'GET' && (event.resource === '/relay/quotas' || event.path === '/relay/quotas')) {
144137
if (!user) {
145138
return await createResponse(401, { error: 'API key required for quota information' });
146139
}
147140

148-
// Return detailed quota information
141+
// Return detailed quota information (always 200, even if exceeded)
149142
const quotaInfo = {
150143
userId: user.userId,
151144
email: user.email,
@@ -163,6 +156,16 @@ exports.handler = async (event, context) => {
163156
return await createResponse(200, quotaInfo, user, usageStatus);
164157
}
165158

159+
// Check daily limit for transaction requests (POST)
160+
if (user && usageStatus && usageStatus.exceeded) {
161+
return await createResponse(429, {
162+
error: 'Daily request limit exceeded',
163+
dailyLimit: usageStatus.dailyLimit,
164+
currentUsage: usageStatus.currentUsage,
165+
resetTime: 'midnight UTC'
166+
}, user, usageStatus);
167+
}
168+
166169
// Initialize provider if not already done
167170
if (!provider || !wallet || !forwarderContract) {
168171
try {

0 commit comments

Comments
 (0)