❌ [ERROR] Error in ProxyController: Error inside ProxyWorker

✘ [ERROR] Error in ProxyController: Error inside ProxyWorker

{
name: 'Error',
message: 'Network connection lost.',
stack: 'Error: Network connection lost.'
}
✘ [ERROR] Error in ProxyController: Error inside ProxyWorker

{
name: 'Error',
message: 'Network connection lost.',
stack: 'Error: Network connection lost.'
}
I am using Hono.js. I encounter an error when repeatedly sending requests, around 10 requests per second, through a middleware. In this middleware, I check if the user's IP is exceed limit in KV and then pass them through the route. The error arises during this process. Middleware
export const CheckLimitExceed = async (c: RequestT, next: Next) => {
try {
const { KV, ENVIRONMENT } = env<ENV>(c, 'workerd');

const ip =
ENVIRONMENT === 'development'
? '127.0.0.1'
: c.req.header('x-real-ip') || c.req.header('cf-connecting-ip');
const key = generateKvKey(ip);
if (!key) {
return c.json(
{
success: false,
err: true,
message: 'Bad Request',
},
400
);
}

const value = await KV.get(key);

if (!value) {
await KV.put(key, '1', { expirationTtl: expire_time });
await next();
return;
}

if (Number(value) >= PER_DAY_SHARING_LIMIT) {
return c.json(
{
success: false,
err: true,
message: `Limit exceeded for today. Please try again later.`,
},
403
);
}

await next();
} catch (err) {
return c.json(
{
success: false,
err: true,
message: 'Internal Server Error',
},
500
);
}
};
export const CheckLimitExceed = async (c: RequestT, next: Next) => {
try {
const { KV, ENVIRONMENT } = env<ENV>(c, 'workerd');

const ip =
ENVIRONMENT === 'development'
? '127.0.0.1'
: c.req.header('x-real-ip') || c.req.header('cf-connecting-ip');
const key = generateKvKey(ip);
if (!key) {
return c.json(
{
success: false,
err: true,
message: 'Bad Request',
},
400
);
}

const value = await KV.get(key);

if (!value) {
await KV.put(key, '1', { expirationTtl: expire_time });
await next();
return;
}

if (Number(value) >= PER_DAY_SHARING_LIMIT) {
return c.json(
{
success: false,
err: true,
message: `Limit exceeded for today. Please try again later.`,
},
403
);
}

await next();
} catch (err) {
return c.json(
{
success: false,
err: true,
message: 'Internal Server Error',
},
500
);
}
};
And pass that middleware like this: Route
router.get('/example/:id', CheckLimitExceed, getData);
router.get('/example/:id', CheckLimitExceed, getData);
1 Reply
James
JamesOP11mo ago
Anyone?
Want results from more Discord servers?
Add your server