Skip to content

Commit

Permalink
rate limiting should follow the same error as the rest
Browse files Browse the repository at this point in the history
  • Loading branch information
VictoriqueMoe committed Mar 13, 2024
1 parent 07e84e9 commit 351ea2a
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/Server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ import { filesDir, FileUtils, NetworkUtils } from "./utils/Utils.js";
import { fileURLToPath } from "node:url";
import { ExpressRateLimitTypeOrmStore } from "typeorm-rate-limit-store";
import { ExpressRateLimitStoreModel } from "./model/db/ExpressRateLimitStore.model.js";
import { Exception, TooManyRequests } from "@tsed/exceptions";
import { DefaultRenderObj } from "./engine/impl/index.js";

const opts: Partial<TsED.Configuration> = {
...config,
Expand Down Expand Up @@ -192,6 +194,7 @@ export class Server implements BeforeRoutesInit {
windowMs: 1000,
limit: 1,
standardHeaders: true,
message: this.parseError(new TooManyRequests("Too many requests, try again later")),
skip: request => {
if (request?.$ctx?.request?.request?.session?.passport) {
return true;
Expand All @@ -205,4 +208,12 @@ export class Server implements BeforeRoutesInit {
}),
);
}

private parseError(error: Exception): DefaultRenderObj {
return {
name: error.origin?.name ?? error.name,
message: error.message,
status: error.status ?? 500,
};
}
}

0 comments on commit 351ea2a

Please sign in to comment.