server for my chess game
Diffstat (limited to 'src/utils.js')
| -rw-r--r-- | src/utils.js | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/utils.js b/src/utils.js index f5a6688..6924fe7 100644 --- a/src/utils.js +++ b/src/utils.js @@ -16,3 +16,18 @@ export function pick(o, ...props) { if (o === undefined) return undefined; return Object.assign({}, ...props.map((prop) => ({ [prop]: o[prop] }))); } + +/** + * Sends a error message on condition + * + * @param {Boolean} when When to fail + * @param {WebSocket} ws The websocket to send the error message to + * @param {String} err The error message + * @param {String} header The header used + * @return {Boolean} `when` + * @exports + */ +export function fail(when, ws, err, header) { + if (when) ws.send_packet({ err: err }, header); + return when; +} |