summary refs log tree commit diff
path: root/api/src/util/ApiError.ts
diff options
context:
space:
mode:
authorFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-09-01 11:27:52 +0200
committerFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-09-01 11:27:52 +0200
commit398e8c29cab05e3d06a73bc9fae3a4ad428c1095 (patch)
treef199eb5184545cb8b0c44ca711691ad2bfe4d3da /api/src/util/ApiError.ts
parentfix #295 (diff)
downloadserver-398e8c29cab05e3d06a73bc9fae3a4ad428c1095.tar.xz
:sparkles: use DiscordApiErrors and check limits
Diffstat (limited to 'api/src/util/ApiError.ts')
-rw-r--r--api/src/util/ApiError.ts38
1 files changed, 21 insertions, 17 deletions
diff --git a/api/src/util/ApiError.ts b/api/src/util/ApiError.ts

index 2316cd71..c133e6e7 100644 --- a/api/src/util/ApiError.ts +++ b/api/src/util/ApiError.ts
@@ -1,23 +1,27 @@ export class ApiError extends Error { - constructor(readonly message: string, public readonly code: number, public readonly httpStatus: number = 400, public readonly defaultParams?: string[]) { - super(message); - } + constructor( + readonly message: string, + public readonly code: number, + public readonly httpStatus: number = 400, + public readonly defaultParams?: string[] + ) { + super(message); + } - withDefaultParams(): ApiError { - if(this.defaultParams) - return new ApiError(applyParamsToString(this.message, this.defaultParams), this.code, this.httpStatus) - return this - } + withDefaultParams(): ApiError { + if (this.defaultParams) return new ApiError(applyParamsToString(this.message, this.defaultParams), this.code, this.httpStatus); + return this; + } - withParams(...params: string[]): ApiError { - return new ApiError(applyParamsToString(this.message, params), this.code, this.httpStatus) - } + withParams(...params: (string | number)[]): ApiError { + return new ApiError(applyParamsToString(this.message, params), this.code, this.httpStatus); + } } -export function applyParamsToString(s: string, params: string[]): string { - let newString = s - params.forEach(a => { - newString = newString.replace("{}", a) - }) - return newString +export function applyParamsToString(s: string, params: (string | number)[]): string { + let newString = s; + params.forEach((a) => { + newString = newString.replace("{}", "" + a); + }); + return newString; }