Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
_decodeMessageBody(body, handle) {
if (handle) {
switch (body.message.handleType) {
case 'net.Server':
return P.resolve([handle]);
case 'http.Server': {
// Wrap net.Server into http.Server.
let ret = http.createServer();
ret.listen(handle);
return P.resolve([ret]);
}
default:
return P.reject(new Error('Unknown handle type: ' + body.message.handleType));
}
}
let message = body.message;
let marshalledTypes = body.marshalledType;
if (!message) {
message = [];
marshalledTypes = [];
}
if (!_.isArray(message)) {
message = [message];
marshalledTypes = [marshalledTypes];
}
}
}
// Add default runtime
if (!this.evt.options.runtime) {
this.evt.options.runtime = 'nodejs';
}
// Check runtime
if (!this.S.classes.Component.getSupportedRuntimes()[this.evt.options.runtime]) {
return BbPromise.reject(new SError('Unsupported runtime ' + this.evt.options.runtime, SError.errorCodes.UNKNOWN));
}
// Check is not reserved name
if (['meta', '_meta', 'plugins'].indexOf(this.evt.options.name) != -1) {
return BbPromise.reject(new SError('This component name is reserved: ' + this.evt.options.name, SError.errorCodes.UNKNOWN));
}
// If component exists in project, throw error
if (this.S.getProject().validateComponentExists(this.evt.options.name, this.S._projectPath)) {
return BbPromise.reject(new SError(
'Component ' + this.evt.options.name + ' already exists',
SError.errorCodes.INVALID_PROJECT_SERVERLESS
));
}
return BbPromise.resolve();
};
this.ready = () => Promise.reject(new Error('You must call hydra.init() before invoking hydra.ready()'));
}
it('should handle any errors that occur:', function () {
var logging = require('./logging');
var response = {
send: _.noop,
status: _.noop
};
sinon.stub(logging, 'error');
sinon.stub(fileStructureUtilsMock, 'getFileStructure').returns(Promise.reject(new Error()));
sinon.spy(response, 'send');
sinon.spy(response, 'status');
return fileStructureModifier.create()(null, response)
.then(function () {
expect(fileStructureUtilsMock.getFileStructure.callCount).to.equal(1);
expect(response.status).to.have.been.calledWith(500);
expect(response.send).to.have.been.calledWith('{"error":"Operation failed."}');
})
.finally(function () {
fileStructureUtilsMock.getFileStructure.restore();
logging.error.restore();
});
});
channels() {
return Promise.reject(new Error('Not supported'));
}
serviceId() {
validateSettings = function validateSettings(defaultSettings, model) {
var values = model.toJSON(),
validationErrors = [],
matchingDefault = defaultSettings[values.key];
if (matchingDefault && matchingDefault.validations) {
validationErrors = validationErrors.concat(validate(values.value, values.key, matchingDefault.validations));
}
if (validationErrors.length !== 0) {
return Promise.reject(validationErrors);
}
return Promise.resolve();
};
.catch(() => Promise.reject(new Error(`Failed to copy over ${filePath}`)));
};
getPlayerRank(competitionId, playerSub) {
if (!competitionId ||
competitionId.length <= 0) {
return Promise.reject(new WrongParameterError('competitionId'));
}
if (!playerSub ||
playerSub.length <= 0) {
return Promise.reject(new WrongParameterError('playerSub'));
}
winston.debug('[LeadsController] getPlayerRank(): competitionId=', competitionId, ' / playerSub=', playerSub);
return Promise
.all([
getRank(competitionId, playerSub),
competitionsController.getPlayersCount(competitionId),
])
.spread((rank, total) => ({rank, total}))
;
////////////
function getRank(cId, pSub) {
return dataProvider.User.findOne({role: 'Owner'}).then(function (owner) {
if (contextUser.id !== owner.id) {
if (editedUserId === owner.id) {
if (owner.related('roles').at(0).id !== roleId) {
return Promise.reject(new errors.NoPermissionError('Cannot change Owner\'s role.'));
}
} else if (roleId !== contextRoleId) {
return canThis(options.context).assign.role(role).then(function () {
return options;
});
}
}
return options;
});
});
public getWiseOperationsRelatedToDelegatorInBlock(delegator: string, blockNum: number): Promise {
return BluebirdPromise.reject(new Error("Not implemented yet"));
}