🎨 move field error to util

This commit is contained in:
Flam3rboy committed 2021-10-05 19:34:13 +02:00
1 parent 9cf018d737
commit 214d6b821c
7 files changed
+6 -8

No files matched your search

+1 -3
View File
@@ -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) {
-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");