How to use http-status-codes - 10 common examples

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 adobe / commerce-cif-magento / test / customer / getCustomerIT.js View on Github external
.then(function (res) {
                    expect(res).to.be.json;
                    expect(res).to.have.status(HttpStatus.OK);

                    // Verify structure
                    requiredFields.verifyCustomer(res.body);
                });
        });
github adobe / commerce-cif-magento / test / carts / getPaymentMethodsIT.js View on Github external
.then(function (res) {
                    expect(res).to.be.json;
                    expect(res).to.have.status(HttpStatus.CREATED);
                    expect(res.body.id).to.not.be.empty;

                    // Store cart id
                    cartId = res.body.id;
                });
        });
github Tangerine-Community / Tangerine / tree / routes / makeApk.js View on Github external
var buildIt = function(doneBuildingIt) {
    cd(`${__dirname}/../client`);
    const buildApk = exec(`npm run build:apk`);
    if (notOk(buildApk, res, HttpStatus.INTERNAL_SERVER_ERROR)) { return; }
    // Make sure the directory is there
    cd(Conf.APP_ROOT_PATH);
    console.log("APK built; moving APK, token: " + token)
    // move the apk to the right directory
    const execer = require('child_process').exec;
    execer(`mv ${Conf.APK_PATH} ${Conf.APP_ROOT_PATH}/apks/${token}`, (error, stdout, stderr) => {
      if (error) {
        console.error(`exec error: ${error}`);
        console.log(`stderr: ${stderr}`);
        return;
      }
      console.log(`stdout: ${stdout}`);
      doneBuildingIt()
    })
  }
github Viveckh / Veniqa / shopping-server / services / userService.js View on Github external
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;
        }
    },
github Viveckh / Veniqa / shopping-server / services / userService.js View on Github external
// 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;
        }
github OliverJAsh / express-result-types / src / result.ts View on Github external
apply(content: C, writeable: Writeable): Result {
        return new Result(this.header, writeable.toEntity(content));
    }
}

// https://github.com/playframework/playframework/blob/49e1bbccdf19501f1c94732ecbef5f4f3ba0ce24/framework/src/play/src/main/scala/play/api/mvc/Results.scala#L664
export const Redirect = (url: string, statusCode: number) =>
    new Status(statusCode).withHeaders(new Map([[Header.Location, url]]));

export const TemporaryRedirect = (url: string): Result =>
    Redirect(url, HttpStatusCodes.TEMPORARY_REDIRECT);

export const Ok = new Status(HttpStatusCodes.OK);
export const BadRequest = new Status(HttpStatusCodes.BAD_REQUEST);
export const InternalServerError = new Status(HttpStatusCodes.INTERNAL_SERVER_ERROR);
github Viveckh / Veniqa / shopping-server / services / userService.js View on Github external
async deleteAddress(userObj, addressId) {
        let result = {};
        try {
            // find the user first
            let user = await User.findOne({email: userObj.email}).exec();

            // 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;
            }

            // Remove the requested address from user
            user = await User.findOneAndUpdate({'addresses._id': addressId}, 
                {$pull: { addresses: { _id: addressId}}},
                {new: true}
                ).exec()

            // 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 deleteAddress Service", {meta: err});
            result = {httpStatus: httpStatus.BAD_REQUEST, status: "failed", errorDetails: err};
github Viveckh / Veniqa / shopping-server / services / securityService.js View on Github external
let token = await cryptoGen.generateRandomToken();
            
            // If an associated user with the email wasn't found, and a token not generated, stop here
            if (!(user && token)) {
                result = {httpStatus: httpStatus.NOT_FOUND, status: "failed", errorDetails: httpStatus.getStatusText(httpStatus.NOT_FOUND)};
                return result;
            }

            // Generate password reset token and save it
            user.passwordResetToken = token;
            user.passwordResetExpires = Date.now() + config.get('token_validity.password_reset_token_valid_for');
            user = await user.save();

            // If the user was not properly saved, stop here and return failure
            if (!user) {
                result = {httpStatus: httpStatus.INTERNAL_SERVER_ERROR, status: "failed", errorDetails: httpStatus.getStatusText(httpStatus.INTERNAL_SERVER_ERROR)};
                return result;
            }

            // If we have gotten this far, return success
            emailService.emailPasswordResetInstructions(user.email, user.name, user.passwordResetToken);
            result = {httpStatus: httpStatus.OK, status: "successful", responseData: true};
            return result;
        }
        catch(err) {
            logger.error("Error in forgotPassword Service", {meta: err});
            result = {httpStatus: httpStatus.BAD_REQUEST, status: "failed", errorDetails: err};
            return result;
        }
    },
github Viveckh / Veniqa / shopping-server / services / shoppingService.js View on Github external
async getCart(userObj, returnAllProductProps=false, save=true) {
        let result = {};
        try {
            let user;
            // find the user first and populate while searching
            if (returnAllProductProps) {
                user = await User.findOne({email: userObj.email}).populate({path: 'cart.items.product', select: '-__v', populate: [{path: 'category', select: '_id category subcategory'}, {path: 'tariff', select: '_id name rates'}]}).exec();
            }
            else {
                user = await User.findOne({email: userObj.email}).populate('cart.items.product', '_id name brand store weight price thumbnailUrls').exec();
            }

            // If the user is not found, its most likely they are not authenticated and don't have user info under session
            if (!user) {
                result = {httpStatus: httpStatus.UNAUTHORIZED, status: "failed", errorDetails: httpStatus.getStatusText(httpStatus.UNAUTHORIZED)};
                return result;
            }

            // If the user doesn't have a cart set up yet, initialize it
            if (!user.cart) {
                user.cart = this.returnFreshInitializedCart();
                result = { httpStatus: httpStatus.OK, status: "successful", responseData: user.cart };
                return result;
            };

            // Remove any existing items from cart which were not found in catalog during population
            _.remove(user.cart.items, (item) => {
                // Returns truthy if product does not have a truthy value
                return !item.product;
            })
github Azure / meta-azure-service-broker / lib / services / azuresqldb / index.js View on Github external
databaseLogin,
        databaseLoginPassword,
        fqdn.replace(/.+\.database/, '*.database.secure'));

        var uri = util.format('mssql://%s:%s@%s:1433/%s?encrypt=true&TrustServerCertificate=false&HostNameInCertificate=%s',
        encodedLogin,
        encodedLoginPassword,
        fqdn,
        sqldbName,
        fqdn.replace(/.+\.database/, '%2A.database')
      );

      // contents of reply.value winds up in VCAP_SERVICES
      var reply = {
        statusCode: HttpStatus.CREATED,
        code: HttpStatus.getStatusText(HttpStatus.CREATED),
        value: {
          credentials: {
            sqldbName: sqldbName,
            sqlServerName: sqlServerName,
            sqlServerFullyQualifiedDomainName: fqdn,
            databaseLogin: databaseLogin,
            databaseLoginPassword: databaseLoginPassword,
            jdbcUrl: jdbcUrl,
            jdbcUrlForAuditingEnabled: jdbcUrlForAuditingEnabled,
            hostname: fqdn,
            port: 1433,
            name: sqldbName,
            username: databaseLogin,
            password: databaseLoginPassword,
            uri: uri
          }