🐛 fix message sending
This commit is contained in:
parent
1350f2cbac
commit
11b2176773
@ -2,7 +2,7 @@ import { NextFunction, Request, Response } from "express";
|
|||||||
import { HTTPError } from "lambert-server";
|
import { HTTPError } from "lambert-server";
|
||||||
import { EntityNotFoundError } from "typeorm";
|
import { EntityNotFoundError } from "typeorm";
|
||||||
import { FieldError } from "../util/instanceOf";
|
import { FieldError } from "../util/instanceOf";
|
||||||
import {ApiError} from "../util/ApiError";
|
import { ApiError } from "../util/ApiError";
|
||||||
|
|
||||||
// TODO: update with new body/typorm validation
|
// TODO: update with new body/typorm validation
|
||||||
export function ErrorHandler(error: Error, req: Request, res: Response, next: NextFunction) {
|
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;
|
code = error.code;
|
||||||
message = error.message;
|
message = error.message;
|
||||||
httpcode = error.httpStatus;
|
httpcode = error.httpStatus;
|
||||||
}
|
} else if (error as EntityNotFoundError) {
|
||||||
else if (error instanceof EntityNotFoundError) {
|
message = `${(error as any).stringifyTarget} could not be found`;
|
||||||
message = `${(error as any).stringifyTarget} can not be found`;
|
|
||||||
code = 404;
|
code = 404;
|
||||||
} else if (error instanceof FieldError) {
|
} else if (error instanceof FieldError) {
|
||||||
code = Number(error.code);
|
code = Number(error.code);
|
||||||
message = error.message;
|
message = error.message;
|
||||||
errors = error.errors;
|
errors = error.errors;
|
||||||
} else {
|
} 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) {
|
if (req.server?.options?.production) {
|
||||||
// don't expose internal errors to the user, instead human errors should be thrown as HTTPError
|
// don't expose internal errors to the user, instead human errors should be thrown as HTTPError
|
||||||
|
@ -20,7 +20,8 @@ router.patch("/", check(MessageCreateSchema), async (req: Request, res: Response
|
|||||||
}
|
}
|
||||||
|
|
||||||
const new_message = await handleMessage({
|
const new_message = await handleMessage({
|
||||||
// TODO: should be message_reference overridable?
|
...message,
|
||||||
|
// TODO: should message_reference be overridable?
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
message_reference: message.message_reference,
|
message_reference: message.message_reference,
|
||||||
...body,
|
...body,
|
||||||
@ -35,7 +36,7 @@ router.patch("/", check(MessageCreateSchema), async (req: Request, res: Response
|
|||||||
await emitEvent({
|
await emitEvent({
|
||||||
event: "MESSAGE_UPDATE",
|
event: "MESSAGE_UPDATE",
|
||||||
channel_id,
|
channel_id,
|
||||||
data: { ...message, nonce: undefined }
|
data: { ...new_message, nonce: undefined }
|
||||||
} as MessageUpdateEvent)
|
} as MessageUpdateEvent)
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
1
bundle/.gitignore
vendored
Normal file
1
bundle/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
files/
|
@ -102,7 +102,7 @@ export class Message extends BaseClass {
|
|||||||
@CreateDateColumn()
|
@CreateDateColumn()
|
||||||
timestamp: Date;
|
timestamp: Date;
|
||||||
|
|
||||||
@Column()
|
@Column({ nullable: true })
|
||||||
edited_timestamp?: Date;
|
edited_timestamp?: Date;
|
||||||
|
|
||||||
@Column({ nullable: true })
|
@Column({ nullable: true })
|
||||||
|
Loading…
x
Reference in New Issue
Block a user