Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function (result, callback) {
if (result.statusCode === HttpStatus.NOT_FOUND) {
callback(null);
} else if (result.statusCode === HttpStatus.OK) {
var error = Error('The database name is not available.');
error.statusCode = HttpStatus.CONFLICT;
callback(error);
} else {
var errorMsg = util.format('sqldb cmd-provision: check existence of sql database, unexpected error: result: %j', result);
log.error(errorMsg);
callback(Error(errorMsg));
}
},
function (callback) { // create the database
import * as HTTPStatus from 'http-status-codes';
import { ErrorType } from '../common/errors';
/**
* Immutable map type specification whose keys are the internal error types, and
* whose values are the matching HTTP error codes.
*/
export type ErrorCodeMap = {
readonly [key in keyof typeof ErrorType]: number;
};
export const ERROR_CODE_MAP: ErrorCodeMap = {
FIELD_VALIDATION_ERROR: HTTPStatus.UNPROCESSABLE_ENTITY, // 422
INTERNAL_SERVER_ERROR: HTTPStatus.INTERNAL_SERVER_ERROR, // 500
NOT_FOUND_ERROR: HTTPStatus.NOT_FOUND, // 404
UNIQUE_CONSTRAINT_ERROR: HTTPStatus.CONFLICT, // 409
VALIDATION_ERROR: HTTPStatus.BAD_REQUEST, // 400
};
export function getHTTPStatusFromErrorCode(errorKey: keyof typeof ErrorType) {
return ERROR_CODE_MAP[errorKey];
}
return response.error(HttpStatus.BAD_REQUEST, 'Invalid specifications for creating room');
}
if (roomSpecification.roomName) { // If User customized his room name
roomSpecification.roomName = roomSetup.utilities.touchupRoomName(roomSpecification.roomName);
const isValidRoomName = roomSetup.utilities.checkIfValidRoomName(roomSpecification.roomName);
if (!isValidRoomName) {
return response.error(HttpStatus.BAD_REQUEST, 'Room name not allowed');
}
} else {
roomSpecification.roomName = roomSetup.getRandomRoomName();
}
// TODO: in case of a random room name I should try a different name
if (Rooms.findOne({ roomName: roomSpecification.roomName, archived: false })) {
return response.error(HttpStatus.CONFLICT, 'A room with same name exists (;一_一)');
}
const { shareChoices } = roomSetup.constants;
const passwordEnabled = roomSpecification.shareChoice === shareChoices.PASSWORD;
const password = passwordEnabled ? roomAccess.hashPassword(roomSpecification.password) : null;
const roomSecret = !passwordEnabled ? Random.secret(10) : null;
const roomId = Random.id(20);
const roomDocument = {
_id: roomId,
provider: 'LICODE',
creatorId: Meteor.userId() || null,
roomName: roomSpecification.roomName,
defaultTab: roomSpecification.defaultTab,
tabs: roomSpecification.tabs,
mysqldbOperations.getServer(function (err, result) {
if (err) {
log.error('cmd-provision: get the mysql server: err: %j', err);
return callback(err);
} else {
log.info('cmd-provision: get the mysql server: %j', result);
if (result.statusCode === HttpStatus.NOT_FOUND) {
callback(null);
} else if (result.statusCode === HttpStatus.OK) { // mysql server exists
var error = Error('The server name is not available.');
error.statusCode = HttpStatus.CONFLICT;
callback(error);
} else {
var errorMessage = util.format('Unexpected result: %j', result);
log.error(errorMessage);
callback(Error(errorMessage));
}
}
});
},
postgresqldbOperations.getServer(function (err, result) {
if (err) {
log.error('cmd-provision: get the postgresql server: err: %j', err);
return callback(err);
}
log.info('cmd-provision: get the postgresql server: %j', result);
if (result.statusCode === HttpStatus.NOT_FOUND) {
callback(null);
} else if (result.statusCode === HttpStatus.OK) { // postgresql server exists
var error = Error('The server name is not available.');
error.statusCode = HttpStatus.CONFLICT;
callback(error);
} else {
var errorMessage = util.format('Unexpected result: %j', result);
log.error(errorMessage);
callback(Error(errorMessage));
}
});
},
Offer: 2,
Order: 3,
PublicKey: 4,
OfferCapReached: 5,
User: 6,
Wallet: 7,
}
},
RequestTimeout: {
code: HttpCodes.REQUEST_TIMEOUT, // 408
types: {
OpenOrderExpired: 1,
}
},
Conflict: {
code: HttpCodes.CONFLICT, // 409
types: {
ExternalOrderAlreadyCompleted: 1,
ExternalOrderByDifferentUser: 2,
CompletedOrderCantTransitionToFailed: 3,
ExternalOrderByDifferentDevice: 4,
UserHasNoWallet: 5
}
},
Gone: {
code: HttpCodes.GONE, // 410
types: {
WrongBlockchainVersion: 1,
}
},
TooManyRequests: {
code: HttpCodes.TOO_MANY_REQUESTS, // 429
if (errors.length === 0) {
try {
const savedNode = await getRepository(ChainlinkNode).save(node)
return res.status(httpStatus.CREATED).json({
id: savedNode.id,
accessKey: savedNode.accessKey,
secret,
})
} catch (e) {
if (
isPostgresError(e) &&
e.code === PostgresErrorCode.UNIQUE_CONSTRAINT_VIOLATION
) {
return res.sendStatus(httpStatus.CONFLICT)
}
console.error(e)
return res.sendStatus(httpStatus.BAD_REQUEST)
}
}
const jsonApiErrors = errors.reduce(
(acc, e) => ({ ...acc, [e.property]: e.constraints }),
{},
)
return res
.status(httpStatus.UNPROCESSABLE_ENTITY)
.send({ errors: jsonApiErrors })
})
cbAddUser(user, (err) => {
if (err) {
console.error(err.code, err.message);
if (err.code === 'ER_DUP_ENTRY') {
rfUtils.error(
res,
httpStatus.CONFLICT,
constants.ERROR_USERALREADYEXISTS,
constants.ERROR_MSG_USERALREADYEXISTS
);
} else {
rfUtils.error(res, httpStatus.INTERNAL_SERVER_ERROR, constants.ERROR_SQL, constants.ERROR_MSG_SQL);
}
return;
}
db.cbFind(db.model.TABLE_USER, {[db.model.ID]: user.ID}, (err, results) => {
if (err) {
console.error(err.code, err.message);
rfUtils.error(res, httpStatus.INTERNAL_SERVER_ERROR, constants.ERROR_SQL, constants.ERROR_MSG_SQL);
return;
}
if (results.length === 0) {
console.log('Registered user is not found');
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);
});
},
cosmosDb.getCosmosDbAccount(resourceGroupName, cosmosDbAccountName, 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 cosmosDb account name is not available.');
error.statusCode = HttpStatus.CONFLICT;
return callback(error);
}
callback(null);
});
},