summary refs log tree commit diff
path: root/gateway/src/opcodes/instanceOf.ts
blob: 6fd5085279bb97da7d29f24d55d60cd9b6a3caa4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import { instanceOf } from "lambert-server";
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;
	}
}