summary refs log tree commit diff
path: root/src/gateway/opcodes/instanceOf.ts
blob: eb6f6ea182839f1b508bff10345ee0b073382f8f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import { instanceOf } from "@fosscord/util";
import { WebSocket } from "@fosscord/gateway";
import { CLOSECODES } from "../util/Constants";

export function check(this: WebSocket, schema: any, data: any) {
	try {
		const error = instanceOf(schema, data, { path: "body" });
		if (error !== true) {
			throw error;
		}
		return true;
	} catch (error) {
		console.error(error);
		// invalid payload
		this.close(CLOSECODES.Decode_error);
		throw error;
	}
}