diff --git a/src/util/util/FieldError.ts b/src/util/util/FieldError.ts
index 3bab92e7..f1976d39 100644
--- a/src/util/util/FieldError.ts
+++ b/src/util/util/FieldError.ts
@@ -16,14 +16,20 @@
along with this program. If not, see .
*/
+export interface FieldErrorResponse {
+ code: number;
+ message: string;
+ errors: Record;
+}
-export function FieldErrors(
- fields: Record,
-) {
+export type ErrorContent = { code: string; message: string };
+export type ObjectErrorContent = { _errors: ErrorContent[] };
+
+export function FieldErrors(fields: Record) {
return new FieldError(
50035,
"Invalid Form Body",
- fields.map(({ message, code }) => ({
+ fields.map(({ message, code }) => ({
_errors: [
{
message,
diff --git a/src/util/util/extensions/Object.test.ts b/src/util/util/extensions/Object.test.ts
index 45023bfd..570b8024 100644
--- a/src/util/util/extensions/Object.test.ts
+++ b/src/util/util/extensions/Object.test.ts
@@ -6,10 +6,10 @@ import assert from "node:assert/strict";
describe("Object extensions", () => {
it("forEach", async () => {
- const obj = { a: 1, b: 2, c: 3 };
+ const obj: { [index:string]: number } = { a: 1, b: 2, c: 3 };
const keys: string[] = [];
const values: number[] = [];
- obj.forEach((value, key) => {
+ obj.forEach((value, key, _) => {
keys.push(key);
values.push(value);
});
diff --git a/src/util/util/extensions/Object.ts b/src/util/util/extensions/Object.ts
index 34bf81a0..17a2204f 100644
--- a/src/util/util/extensions/Object.ts
+++ b/src/util/util/extensions/Object.ts
@@ -1,31 +1,34 @@
declare global {
interface Object {
- forEach(callback: (value: unknown, key: string, object: unknown) => void): void;
- map(callback: (value: unknown, key: string, object: unknown) => T): object;
+ forEach(callback: (value: T, key: string, object: { [index: string]: T }) => void): void;
+ map(callback: (value: SV, key: string, object: { [index: string]: SV }) => TV): { [index: string]: TV };
}
}
-export function objectForEach(obj: never, callback: (value: T, key: string, object: unknown) => void): void {
+export function objectForEach(obj: { [index: string]: T }, callback: (value: T, key: string, object: { [index: string]: T }) => void): void {
Object.keys(obj).forEach((key) => {
callback(obj[key], key, obj);
});
}
-export function objectMap(obj: object, callback: (value: unknown, key: string, object: unknown) => T): T[] {
- return Object.keys(obj).map((key) => {
- return callback(obj[key], key, obj);
+export function objectMap(srcObj: { [index: string]: SV }, callback: (value: SV, key: string, object: { [index: string]: SV }) => TV): { [index: string]: TV } {
+ if (typeof callback !== "function") throw new TypeError(`${callback} is not a function`);
+ const obj: { [index: string]: TV } = {};
+ Object.keys(srcObj).forEach((key) => {
+ obj[key] = callback(srcObj[key], key, srcObj);
});
+ return obj;
}
if (!Object.prototype.forEach)
Object.defineProperty(Object.prototype, "forEach", {
value: objectForEach,
enumerable: false,
- writable: true
+ writable: true,
});
if (!Object.prototype.map)
Object.defineProperty(Object.prototype, "map", {
value: objectMap,
enumerable: false,
- writable: true
- });
\ No newline at end of file
+ writable: true,
+ });
diff --git a/src/util/util/lambert-server/Server.ts b/src/util/util/lambert-server/Server.ts
index 43701d04..b8f4c491 100644
--- a/src/util/util/lambert-server/Server.ts
+++ b/src/util/util/lambert-server/Server.ts
@@ -2,7 +2,7 @@ import express, { Application, NextFunction, Request, Response, Router } from "e
import { traverseDirectory } from "./Utils";
import { Server as HTTPServer } from "http";
import { HTTPError } from "./HTTPError";
-import "express-async-errors";
+// import "express-async-errors";
import bodyParser from "body-parser";
// import helmet from "helmet";
import http from "http";