ProposalLimiter, in the presenters, asked for the RateLimitStore port, which only the application layer sees, so Nest could not build it and the container never became healthy. The count now lives in an application service, ProposalQuota; the presenter only answers 429. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
17 lines
558 B
TypeScript
17 lines
558 B
TypeScript
import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
|
|
import { ProposalQuota } from '@task-stream/api/tracker/application';
|
|
|
|
/** The proposal quota, as the HTTP answer: 429 once it is used up. */
|
|
@Injectable()
|
|
export class ProposalLimiter {
|
|
constructor(private readonly quota: ProposalQuota) {}
|
|
|
|
async take(address: string): Promise<void> {
|
|
if (!(await this.quota.take(address)))
|
|
throw new HttpException(
|
|
'Too many proposals from here; try again in a few minutes',
|
|
HttpStatus.TOO_MANY_REQUESTS,
|
|
);
|
|
}
|
|
}
|