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