🎨 move field error to util
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
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,}))$/;
|
||||
|
||||
export function adjustEmail(email: string): string | undefined {
|
||||
export function adjustEmail(email?: string): string | undefined {
|
||||
if (!email) return email;
|
||||
// body parser already checked if it is a valid email
|
||||
const parts = <RegExpMatchArray>email.match(EMAIL_REGEX);
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -5,8 +5,9 @@ export * from "./cdn";
|
||||
export * from "./Config";
|
||||
export * from "./Constants";
|
||||
export * from "./Database";
|
||||
export * from "./Event";
|
||||
export * from "./Email";
|
||||
export * from "./Event";
|
||||
export * from "./FieldError";
|
||||
export * from "./Intents";
|
||||
export * from "./MessageFlags";
|
||||
export * from "./Permissions";
|
||||
|
||||
Reference in New Issue
Block a user