Add assert to messages endpoint

This commit is contained in:
Fedor Indutny 2021-07-29 01:20:18 -07:00 committed by GitHub
parent 4a402126b4
commit 0acefaa656
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -29,7 +29,7 @@ import { v4 as getGuid } from 'uuid';
import { z } from 'zod';
import Long from 'long';
import { assert } from '../util/assert';
import { assert, strictAssert } from '../util/assert';
import { getUserAgent } from '../util/getUserAgent';
import { toWebSafeBase64 } from '../util/webSafeBase64';
import { SocketStatus } from '../types/SocketStatus';
@ -1707,6 +1707,12 @@ export function initialize({
}).then(handleKeys);
}
function validateMessages(messages: Array<unknown>): void {
for (const message of messages) {
strictAssert(message !== null, 'Attempting to send `null` message');
}
}
async function sendMessagesUnauth(
destination: string,
messageArray: Array<MessageType>,
@ -1720,6 +1726,8 @@ export function initialize({
jsonData.online = true;
}
validateMessages(messageArray);
return _ajax({
call: 'messages',
httpType: 'PUT',
@ -1743,6 +1751,8 @@ export function initialize({
jsonData.online = true;
}
validateMessages(messageArray);
return _ajax({
call: 'messages',
httpType: 'PUT',