diff options
author | Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> | 2021-10-05 19:34:13 +0200 |
---|---|---|
committer | Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> | 2021-10-05 19:34:13 +0200 |
commit | 1492751d58ba74c5525d5f6e846a079ca91ad15f (patch) | |
tree | f95db213a836803a64926804a6b9b111bf9b8957 /api | |
parent | :sparkles: add User.register() method (diff) | |
download | server-1492751d58ba74c5525d5f6e846a079ca91ad15f.tar.xz |
:art: move field error to util
Diffstat (limited to 'api')
-rw-r--r-- | api/src/middlewares/ErrorHandler.ts | 4 | ||||
-rw-r--r-- | api/src/util/FieldError.ts | 25 | ||||
-rw-r--r-- | api/src/util/String.ts | 2 | ||||
-rw-r--r-- | api/src/util/index.ts | 1 | ||||
-rw-r--r-- | api/src/util/route.ts | 2 |
5 files changed, 3 insertions, 31 deletions
diff --git a/api/src/middlewares/ErrorHandler.ts b/api/src/middlewares/ErrorHandler.ts index 96e703ce..2012b91c 100644 --- a/api/src/middlewares/ErrorHandler.ts +++ b/api/src/middlewares/ErrorHandler.ts @@ -1,8 +1,6 @@ import { NextFunction, Request, Response } from "express"; import { HTTPError } from "lambert-server"; -import { EntityNotFoundError } from "typeorm"; -import { FieldError } from "@fosscord/api"; -import { ApiError } from "@fosscord/util"; +import { ApiError, FieldError } from "@fosscord/util"; const EntityNotFoundErrorRegex = /"(\w+)"/; export function ErrorHandler(error: Error, req: Request, res: Response, next: NextFunction) { diff --git a/api/src/util/FieldError.ts b/api/src/util/FieldError.ts deleted file mode 100644 index 0b3f93d2..00000000 --- a/api/src/util/FieldError.ts +++ /dev/null @@ -1,25 +0,0 @@ -import "missing-native-js-functions"; - -export function FieldErrors(fields: Record<string, { code?: string; message: string }>) { - return new FieldError( - 50035, - "Invalid Form Body", - fields.map(({ message, code }) => ({ - _errors: [ - { - message, - code: code || "BASE_TYPE_INVALID" - } - ] - })) - ); -} - -// TODO: implement Image data type: Data URI scheme that supports JPG, GIF, and PNG formats. An example Data URI format is: data:image/jpeg;base64,BASE64_ENCODED_JPEG_IMAGE_DATA -// Ensure you use the proper content type (image/jpeg, image/png, image/gif) that matches the image data being provided. - -export class FieldError extends Error { - constructor(public code: string | number, public message: string, public errors?: any) { - super(message); - } -} diff --git a/api/src/util/String.ts b/api/src/util/String.ts index 67d87e37..982b7e11 100644 --- a/api/src/util/String.ts +++ b/api/src/util/String.ts @@ -1,6 +1,6 @@ import { Request } from "express"; import { ntob } from "./Base64"; -import { FieldErrors } from "./FieldError"; +import { FieldErrors } from "@fosscord/util"; export function checkLength(str: string, min: number, max: number, key: string, req: Request) { if (str.length < min || str.length > max) { diff --git a/api/src/util/index.ts b/api/src/util/index.ts index 3e47ce4e..238787c9 100644 --- a/api/src/util/index.ts +++ b/api/src/util/index.ts @@ -1,5 +1,4 @@ export * from "./Base64"; -export * from "./FieldError"; export * from "./ipAddress"; export * from "./Message"; export * from "./passwordStrength"; diff --git a/api/src/util/route.ts b/api/src/util/route.ts index 3e967e2a..e4794eb5 100644 --- a/api/src/util/route.ts +++ b/api/src/util/route.ts @@ -3,6 +3,7 @@ import { EVENT, Event, EventData, + FieldErrors, FosscordApiErrors, getPermission, PermissionResolvable, @@ -15,7 +16,6 @@ import fs from "fs"; import path from "path"; import Ajv from "ajv"; import { AnyValidateFunction } from "ajv/dist/core"; -import { FieldErrors } from ".."; import addFormats from "ajv-formats"; const SchemaPath = path.join(__dirname, "..", "..", "assets", "schemas.json"); |