How to use the http-status-codes.NOT_FOUND 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 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 adobe / commerce-cif-magento / test / carts / deleteCouponIT.js View on Github external
.then(function(res) {
                    expect(res).to.have.status(HttpStatus.NOT_FOUND);
                    expect(res).to.be.json;
                    requiredFields.verifyErrorResponse(res.body);
                });
        });
github adobe / commerce-cif-magento / test / carts / postCartEntryIT.js View on Github external
.then(function(res) {
                    expect(res).to.have.status(HttpStatus.NOT_FOUND);
                    expect(res).to.be.json;
                    requiredFields.verifyErrorResponse(res.body);
                });
        })
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 JonathanWexler / get-programming-with-nodejs / unit_4 / lesson_18 / finish / recipe_app_18_3 / controllers / errorController.js View on Github external
exports.respondNoResourceFound = (req, res) => {
  let errorCode = httpStatus.NOT_FOUND;
  res.status(errorCode);
  res.send(`${errorCode} | The page does not exist!`);
};
github RouteInjector / route-injector / lib / engine / routeinjector / rest / get.js View on Github external
function checkDocument(doc) {
                if (!doc) {
                    res.statusCode = statusCode.NOT_FOUND;
                    throw new Error('Document not found');
                }
                return doc;
            }
github fbsamples / typefast / server / src / server / controllers / ScriptRestController.js View on Github external
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();
    });
  }
github microsoft / BotFramework-Emulator / packages / app / main / src / server / routes / channel / attachments / handlers / getAttachment.ts View on Github external
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`
          )
github Azure / meta-azure-service-broker / lib / services / azurepostgresqldb / cmd-poll.js View on Github external
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);
                    }
                });
            }
github microsoft / BotFramework-Emulator / src / server / controllers / connector / botStateController.ts View on Github external
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);
        }