How to use the http-status-codes.CONFLICT function in http-status-codes

To help you get started, we’ve selected a few http-status-codes examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Azure / meta-azure-service-broker / lib / services / azuresqldb / cmd-provision.js View on Github external
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
github dstack-group / Butterfly / user-manager / user-manager-rest-api / src / errors / errorCodeMap.ts View on Github external
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];
}
github akshaykmr / oorja / app / imports / startup / server / rpc / room.js View on Github external
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,
github Azure / meta-azure-service-broker / lib / services / azuremysqldb / cmd-provision.js View on Github external
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));
                        }
                    }
                });
            },
github Azure / meta-azure-service-broker / lib / services / azurepostgresqldb / cmd-provision.js View on Github external
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));
                    }
                });
            },
github kinecosystem / marketplace-server / scripts / src / errors.ts View on Github external
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
github smartcontractkit / chainlink / explorer / src / controllers / admin / nodes.ts View on Github external
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 })
})
github re-figure / refigure / back / users.js View on Github external
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');
github Azure / meta-azure-service-broker / lib / services / azuredocdb / cmd-provision.js View on Github external
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);
        });
      },
github Azure / meta-azure-service-broker / lib / services / azurecosmosdb / cmd-provision.js View on Github external
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);
        });
      },