Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// If user is not authenticated or the user does not exist in system - stop
// If so do not continue further
if (!user) {
result = {httpStatus: httpStatus.UNAUTHORIZED, status: "failed", errorDetails: httpStatus.getStatusText(httpStatus.UNAUTHORIZED)};
return result;
}
// Validate that the address item matches by doing a match using the _ids
let index = _.findIndex(user.addresses, (obj) => {
return obj._id.toString() == addressObj._id;
});
// If the address is not found, return failure
if (index == -1) {
result = {httpStatus: httpStatus.NOT_FOUND, status: "failed", errorDetails: httpStatus.getStatusText(httpStatus.NOT_FOUND)};
return result;
}
// Otherwise, Update the address values
user.addresses[index] = addressObj;
user = await user.save();
// Return the proper response depending on whether save was successful
result = user ? {httpStatus: httpStatus.OK, status: "successful", responseData: user.addresses} : {httpStatus: httpStatus.BAD_REQUEST, status: "failed", errorDetails: httpStatus.getStatusText(httpStatus.BAD_REQUEST)};
return result;
}
catch(err) {
logger.error("Error in updateAddress Service", {meta: err});
result = {httpStatus: httpStatus.BAD_REQUEST, status: "failed", errorDetails: err};
return result;
}
.then(function(res) {
expect(res).to.have.status(HttpStatus.NOT_FOUND);
expect(res).to.be.json;
requiredFields.verifyErrorResponse(res.body);
});
});
.then(function(res) {
expect(res).to.have.status(HttpStatus.NOT_FOUND);
expect(res).to.be.json;
requiredFields.verifyErrorResponse(res.body);
});
})
docDb.getDocDbAccount(resourceGroupName, docDbAccountName, function(err, res, body) {
if (err) {
return callback(err);
}
if (res.statusCode != HttpStatus.NOT_FOUND && res.statusCode != HttpStatus.NO_CONTENT) {
var error = new Error('The docDb account name is not available.');
error.statusCode = HttpStatus.CONFLICT;
return callback(error);
}
callback(null);
});
},
exports.respondNoResourceFound = (req, res) => {
let errorCode = httpStatus.NOT_FOUND;
res.status(errorCode);
res.send(`${errorCode} | The page does not exist!`);
};
function checkDocument(doc) {
if (!doc) {
res.statusCode = statusCode.NOT_FOUND;
throw new Error('Document not found');
}
return doc;
}
Script.findById(id, (err: Error, script: ?Document) => {
if (err) {
this.returnError(request, response, HttpStatus.INTERNAL_SERVER_ERROR);
return;
}
if (script == null) {
this.returnError(request, response, HttpStatus.NOT_FOUND);
return;
}
response.send(script).end();
});
}
let buffer;
if (attachmentBase64.buffer) {
buffer = Buffer.from(attachmentBase64 as any);
} else {
buffer = Buffer.from(attachmentBase64.toString(), 'base64');
}
res.contentType = attachment.type;
res.send(HttpStatus.OK, buffer);
} else {
sendErrorResponse(
req,
res,
next,
createAPIException(
HttpStatus.NOT_FOUND,
ErrorCodes.BadArgument,
params.viewId === 'original' ? 'There is no original view' : 'There is no thumbnail view'
)
);
}
}
} else {
sendErrorResponse(
req,
res,
next,
createAPIException(
HttpStatus.NOT_FOUND,
ErrorCodes.BadArgument,
`attachment[${params.attachmentId}] not found`
)
postgresqldbOperations.getServer(function (err, result) {
if (err) {
log.error('cmd-poll: check existence of postgresql server: err: %j', err);
next(err);
} else {
log.info('cmd-poll: check existence of postgresql server: result: %j', result);
if (result.statusCode === HttpStatus.NOT_FOUND) {
reply.state = 'succeeded';
reply.description = 'Server has been deleted.';
} else {
reply.state = 'failed';
reply.description = 'Failed to delete server.';
}
next(null, pollingResult);
}
});
}
public deleteStateForUser = (req: Restify.Request, res: Restify.Response, next: Restify.Next): any => {
try {
const activeBot = getSettings().getActiveBot();
if (!activeBot) {
throw ResponseTypes.createAPIException(HttpStatus.NOT_FOUND, ErrorCodes.BadArgument, "bot not found");
}
let keys = Object.keys(this.botDataStore);
for (let i = 0; i < keys.length; i++) {
let key = keys[i];
if (key.startsWith(`${activeBot.botId}!`) && key.endsWith(`!${req.params.userId}`)) {
delete this.botDataStore[key];
}
}
res.send(HttpStatus.OK);
res.end();
log.api('deleteStateForUser', req, res, req.params, null);
} catch (err) {
var error = ResponseTypes.sendErrorResponse(req, res, next, err);
log.api('deleteStateForUser', req, res, req.params, error);
}