From: Alexander Ebert Date: Sun, 17 Mar 2024 15:24:07 +0000 (+0100) Subject: Add a helper method to identify validation errors X-Git-Tag: 6.1.0_Alpha_1~148^2~8 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=6a37263d165bbefd43cb507f8c115e64e7a8970d;p=GitHub%2FWoltLab%2FWCF.git Add a helper method to identify validation errors --- diff --git a/ts/WoltLabSuite/Core/Api/Error.ts b/ts/WoltLabSuite/Core/Api/Error.ts index b09ba2697e..36078cbddf 100644 --- a/ts/WoltLabSuite/Core/Api/Error.ts +++ b/ts/WoltLabSuite/Core/Api/Error.ts @@ -6,5 +6,22 @@ export class ApiError { public readonly code: string, public readonly message: string, public readonly param: string, + public readonly statusCode: number, + ) {} + + getValidationError(): ValidationError | undefined { + if (this.type !== "invalid_request_error" || this.statusCode !== 400) { + return undefined; + } + + return new ValidationError(this.code, this.message, this.param); + } +} + +class ValidationError { + constructor( + public readonly code: string, + public readonly message: string, + public readonly param: string, ) {} } diff --git a/ts/WoltLabSuite/Core/Api/Result.ts b/ts/WoltLabSuite/Core/Api/Result.ts index 138e1990f1..92fb7b3b67 100644 --- a/ts/WoltLabSuite/Core/Api/Result.ts +++ b/ts/WoltLabSuite/Core/Api/Result.ts @@ -62,7 +62,7 @@ export async function apiResultFromStatusNotOk(e: StatusNotOk): Promise