Handle the case where no socket.io ack exists
This commit is contained in:
parent
9dc82ad444
commit
0613083eb0
3 changed files with 43 additions and 0 deletions
|
|
@ -2,6 +2,7 @@ var ChannelModule = require("./module");
|
|||
var Poll = require("../poll").Poll;
|
||||
import { ValidationError } from '../errors';
|
||||
import Config from '../config';
|
||||
import { ackOrErrorMsg } from '../util/ack';
|
||||
|
||||
const TYPE_NEW_POLL = {
|
||||
title: "string",
|
||||
|
|
@ -160,6 +161,8 @@ PollModule.prototype.handleNewPoll = function (user, data, ack) {
|
|||
return;
|
||||
}
|
||||
|
||||
ack = ackOrErrorMsg(ack, user);
|
||||
|
||||
if (typeof data !== 'object' || data === null) {
|
||||
ack({
|
||||
error: {
|
||||
|
|
|
|||
11
src/util/ack.js
Normal file
11
src/util/ack.js
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
export function ackOrErrorMsg(ack, user) {
|
||||
if (typeof ack === 'function') {
|
||||
return ack;
|
||||
}
|
||||
|
||||
return (result) => {
|
||||
if (result.error) {
|
||||
user.socket.emit('errorMsg', { msg: result.error.message });
|
||||
}
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue