Skip to content

Commit

Permalink
Merge pull request #104 from waifuvault/rate-limit-real-error
Browse files Browse the repository at this point in the history
rate limiting should follow the same error as the rest
  • Loading branch information
VictoriqueMoe authored Mar 13, 2024
2 parents 07e84e9 + 351ea2a commit a8ce250
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 a8ce250

Please sign in to comment.