🎨 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

View File

@ -1,8 +1,6 @@
import { NextFunction, Request, Response } from "express"; import { NextFunction, Request, Response } from "express";
import { HTTPError } from "lambert-server"; import { HTTPError } from "lambert-server";
import { EntityNotFoundError } from "typeorm"; import { ApiError, FieldError } from "@fosscord/util";
import { FieldError } from "@fosscord/api";
import { ApiError } from "@fosscord/util";
const EntityNotFoundErrorRegex = /"(\w+)"/; const EntityNotFoundErrorRegex = /"(\w+)"/;
export function ErrorHandler(error: Error, req: Request, res: Response, next: NextFunction) { export function ErrorHandler(error: Error, req: Request, res: Response, next: NextFunction) {

View File

@ -1,6 +1,6 @@
import { Request } from "express"; import { Request } from "express";
import { ntob } from "./Base64"; 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) { export function checkLength(str: string, min: number, max: number, key: string, req: Request) {
if (str.length < min || str.length > max) { if (str.length < min || str.length > max) {

View File

@ -1,5 +1,4 @@
export * from "./Base64"; export * from "./Base64";
export * from "./FieldError";
export * from "./ipAddress"; export * from "./ipAddress";
export * from "./Message"; export * from "./Message";
export * from "./passwordStrength"; export * from "./passwordStrength";

View File

@ -3,6 +3,7 @@ import {
EVENT, EVENT,
Event, Event,
EventData, EventData,
FieldErrors,
FosscordApiErrors, FosscordApiErrors,
getPermission, getPermission,
PermissionResolvable, PermissionResolvable,
@ -15,7 +16,6 @@ import fs from "fs";
import path from "path"; import path from "path";
import Ajv from "ajv"; import Ajv from "ajv";
import { AnyValidateFunction } from "ajv/dist/core"; import { AnyValidateFunction } from "ajv/dist/core";
import { FieldErrors } from "..";
import addFormats from "ajv-formats"; import addFormats from "ajv-formats";
const SchemaPath = path.join(__dirname, "..", "..", "assets", "schemas.json"); const SchemaPath = path.join(__dirname, "..", "..", "assets", "schemas.json");

View File

@ -1,7 +1,7 @@
export const EMAIL_REGEX = export const EMAIL_REGEX =
/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
export function adjustEmail(email: string): string | undefined { export function adjustEmail(email?: string): string | undefined {
if (!email) return email; if (!email) return email;
// body parser already checked if it is a valid email // body parser already checked if it is a valid email
const parts = <RegExpMatchArray>email.match(EMAIL_REGEX); const parts = <RegExpMatchArray>email.match(EMAIL_REGEX);

View File

@ -5,8 +5,9 @@ export * from "./cdn";
export * from "./Config"; export * from "./Config";
export * from "./Constants"; export * from "./Constants";
export * from "./Database"; export * from "./Database";
export * from "./Event";
export * from "./Email"; export * from "./Email";
export * from "./Event";
export * from "./FieldError";
export * from "./Intents"; export * from "./Intents";
export * from "./MessageFlags"; export * from "./MessageFlags";
export * from "./Permissions"; export * from "./Permissions";