summary refs log tree commit diff
path: root/util/src
diff options
context:
space:
mode:
authorFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-10-05 19:34:13 +0200
committerFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-10-05 19:34:13 +0200
commit1492751d58ba74c5525d5f6e846a079ca91ad15f (patch)
treef95db213a836803a64926804a6b9b111bf9b8957 /util/src
parent:sparkles: add User.register() method (diff)
downloadserver-1492751d58ba74c5525d5f6e846a079ca91ad15f.tar.xz
:art: move field error to util
Diffstat (limited to 'util/src')
-rw-r--r--util/src/util/Email.ts2
-rw-r--r--util/src/util/FieldError.ts25
-rw-r--r--util/src/util/index.ts3
3 files changed, 28 insertions, 2 deletions
diff --git a/util/src/util/Email.ts b/util/src/util/Email.ts
index c304f584..b1a7599b 100644
--- a/util/src/util/Email.ts
+++ b/util/src/util/Email.ts
@@ -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);
diff --git a/util/src/util/FieldError.ts b/util/src/util/FieldError.ts
new file mode 100644
index 00000000..0b3f93d2
--- /dev/null
+++ b/util/src/util/FieldError.ts
@@ -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);
+	}
+}
diff --git a/util/src/util/index.ts b/util/src/util/index.ts
index 9c51d3b8..67583635 100644
--- a/util/src/util/index.ts
+++ b/util/src/util/index.ts
@@ -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";