🎨 move field error to util

This commit is contained in:
Flam3rboy
2021-10-05 19:34:13 +02:00
parent 9cf018d737
commit 214d6b821c
7 changed files with 6 additions and 8 deletions
-25
View File
@@ -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);
}
}
+1 -1
View File
@@ -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) {
-1
View File
@@ -1,5 +1,4 @@
export * from "./Base64";
export * from "./FieldError";
export * from "./ipAddress";
export * from "./Message";
export * from "./passwordStrength";
+1 -1
View File
@@ -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");