From e662c983b31b5f437084f1b78b542d67fbda3182 Mon Sep 17 00:00:00 2001 From: Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> Date: Fri, 3 Sep 2021 04:04:34 +0200 Subject: [PATCH] :bug: fix message sending --- api/src/middlewares/ErrorHandler.ts | 9 ++++----- .../channels/#channel_id/messages/#message_id/index.ts | 5 +++-- bundle/.gitignore | 1 + util/src/entities/Message.ts | 2 +- 4 files changed, 9 insertions(+), 8 deletions(-) create mode 100644 bundle/.gitignore diff --git a/api/src/middlewares/ErrorHandler.ts b/api/src/middlewares/ErrorHandler.ts index f061172a..34827cab 100644 --- a/api/src/middlewares/ErrorHandler.ts +++ b/api/src/middlewares/ErrorHandler.ts @@ -2,7 +2,7 @@ import { NextFunction, Request, Response } from "express"; import { HTTPError } from "lambert-server"; import { EntityNotFoundError } from "typeorm"; import { FieldError } from "../util/instanceOf"; -import {ApiError} from "../util/ApiError"; +import { ApiError } from "../util/ApiError"; // TODO: update with new body/typorm validation export function ErrorHandler(error: Error, req: Request, res: Response, next: NextFunction) { @@ -19,16 +19,15 @@ export function ErrorHandler(error: Error, req: Request, res: Response, next: Ne code = error.code; message = error.message; httpcode = error.httpStatus; - } - else if (error instanceof EntityNotFoundError) { - message = `${(error as any).stringifyTarget} can not be found`; + } else if (error as EntityNotFoundError) { + message = `${(error as any).stringifyTarget} could not be found`; code = 404; } else if (error instanceof FieldError) { code = Number(error.code); message = error.message; errors = error.errors; } else { - console.error(`[Error] ${code} ${req.url}`, errors || error, "body:", req.body); + console.error(`[Error] ${code} ${req.url}\n`, errors || error, "\nbody:", req.body); if (req.server?.options?.production) { // don't expose internal errors to the user, instead human errors should be thrown as HTTPError diff --git a/api/src/routes/channels/#channel_id/messages/#message_id/index.ts b/api/src/routes/channels/#channel_id/messages/#message_id/index.ts index 9c631a18..7a00de43 100644 --- a/api/src/routes/channels/#channel_id/messages/#message_id/index.ts +++ b/api/src/routes/channels/#channel_id/messages/#message_id/index.ts @@ -20,7 +20,8 @@ router.patch("/", check(MessageCreateSchema), async (req: Request, res: Response } const new_message = await handleMessage({ - // TODO: should be message_reference overridable? + ...message, + // TODO: should message_reference be overridable? // @ts-ignore message_reference: message.message_reference, ...body, @@ -35,7 +36,7 @@ router.patch("/", check(MessageCreateSchema), async (req: Request, res: Response await emitEvent({ event: "MESSAGE_UPDATE", channel_id, - data: { ...message, nonce: undefined } + data: { ...new_message, nonce: undefined } } as MessageUpdateEvent) ]); diff --git a/bundle/.gitignore b/bundle/.gitignore new file mode 100644 index 00000000..7d2cb508 --- /dev/null +++ b/bundle/.gitignore @@ -0,0 +1 @@ +files/ \ No newline at end of file diff --git a/util/src/entities/Message.ts b/util/src/entities/Message.ts index 623c9168..f4c7fdc7 100644 --- a/util/src/entities/Message.ts +++ b/util/src/entities/Message.ts @@ -102,7 +102,7 @@ export class Message extends BaseClass { @CreateDateColumn() timestamp: Date; - @Column() + @Column({ nullable: true }) edited_timestamp?: Date; @Column({ nullable: true })