当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript Response.sendStatus方法代码示例

本文整理汇总了TypeScript中express.Response.sendStatus方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Response.sendStatus方法的具体用法?TypeScript Response.sendStatus怎么用?TypeScript Response.sendStatus使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在express.Response的用法示例。


在下文中一共展示了Response.sendStatus方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: function

router.post('/login', function(req: Request, res: Response, next: Function) {
    let username = req.body.username;
    let password = req.body.password;
    let user = UserService.findById(username);
    if(user && (password === user.password)) {
        res.set('jwt', jsonwebtoken.sign({sub: user.id}, 'secret'));
        res.sendStatus(200);
    } else {
        res.sendStatus(403);
    }
});
开发者ID:DaniOtero,项目名称:jwt-express-demo,代码行数:11,代码来源:user.ts

示例2: handleError

	/**
	 * ErrorHandler method for all Request classes.
	 * If the err parameter is of type object the object is logged and error code
	 * 500 is added to the response. If the err parameter is of type number the number
	 * is send as statusCode to the client. If none of these is true statusCode 500 is send
	 * to the client and an 'undefined error' is logged.
	 * @param err error object or statusCode
	 * @param res response object that holds the data send to the client
     */
	handleError(err, res:Response) {
		if (typeof err === 'object') {
			console.error(err);
			res.status(500).send(err.toString());
		} else if (typeof err === 'number') {
			res.sendStatus(err);
		} else {
			console.error('undefined error');
			res.sendStatus(500);
		}
	}
开发者ID:draschke,项目名称:n-odata-server,代码行数:20,代码来源:BaseRequestHandler.ts

示例3: function

module.exports = function (req: Request, res: Response, next: any) {
  // User is allowed, proceed to controller
  var is_auth = req.isAuthenticated();
  if (is_auth) return next();
  // User is not allowed
  return res.sendStatus(401);
};
开发者ID:twicepixels,项目名称:tp-main-api,代码行数:7,代码来源:authenticated.ts

示例4: async

router.post('/', async (req: Request, res: Response, next: NextFunction) => {
    if (!req.body.hasOwnProperty('publicId')) {
        const err = new Error('Request lacked a publicId');
        res.status(400);
        return next(err);
    }

    const publicId = req.body.publicId;

    try {
        await db.markMessagesUnread(
            req.user,
            [publicId],
        );

        const message = await db.getMessage(req.user, publicId);

        publishMessage(req.app, req.user, message);

        res.sendStatus(204);
        return;
    } catch (e) {
        return res.status(500).json(e);
    }
});
开发者ID:lovett,项目名称:notifier,代码行数:25,代码来源:unclear.ts

示例5:

 productService.retrieveProduct(req.params.name).then((product: ProductInstance) => {
   if (product) {
     return res.send(product);
   } else {
     return res.sendStatus(404);
   }
 }).catch((error: Error) => {
开发者ID:natarajanmca11,项目名称:sequelize-typescript-examples,代码行数:7,代码来源:product-router.ts

示例6: ensureUser

function ensureUser(req: Request, res: Response, next: NextFunction) {
  if (req.user) {
    next();
  } else {
    res.sendStatus(401);
  }
}
开发者ID:odetown,项目名称:golfdraft,代码行数:7,代码来源:authMiddleware.ts

示例7:

	}, (status, body) => {
		if (body == null || body == '') {
			res.sendStatus(status);
		} else {
			res.status(status).send(body);
		}
	}, next);
开发者ID:syuilo,项目名称:accesses,代码行数:7,代码来源:express.ts

示例8: async

router.post('/', async (req: Request, res: Response) => {
    const additions: Token[] = [];
    const removals: string[] = [];
    const whitelist = ['webhook'];

    for (const name in req.body) {
        if (whitelist.indexOf(name) === -1) {
            continue;
        }

        removals.push(name);

        if (req.body[name].trim().length === 0) {
            continue;
        }

        const token = new Token('userval', true, name, req.body[name]);

        additions.push(token);
    }

    if (removals.length === 0 && additions.length === 0) {
        res.status(400).send('Nothing to be done');
        return;
    }

    try {
        await db.deleteTokensByKey(req.user, removals);
        await db.addTokens(req.user, additions);
        return res.sendStatus(200);
    } catch (e) {
        return res.status(500).json(e);
    }
});
开发者ID:lovett,项目名称:notifier,代码行数:34,代码来源:services.ts

示例9: async

 get: async (req: RequestEx, res: Response) => {
     let range = req.query.range;
     
     if (req.query.range != null) {
         range = Range
     }
     
     if (range === undefined) {
         range = null;
     }
     
     let amenities: number[]; 
     
     if(_.isArray(req.query.amenities)) {
         amenities = req.query.amenities
     } else if (req.query.amenities != null) {
         amenities = [req.query.amenities]
     } else {
         amenities = [];
     }
     
     const params = {
         query: req.query.q || "",
         range,
         amenities: amenities
     }
     
     try {
         const lodgings = await getClient().manyOrNone(query, params);
         res.send(lodgings);
     } catch (e) {
         console.log(e);
         res.sendStatus(400);
     }
 }
开发者ID:paavohuhtala,项目名称:lodgist,代码行数:35,代码来源:LodgingSearch.ts

示例10: catch

router.get('/', (req: Request, res: Response, next: Function) => {
    try {
        let notes = UserService.findById(req.user.id).notes;
        res.json({notes: notes});
    } catch(err) {
        res.sendStatus(400);
    }
});
开发者ID:DaniOtero,项目名称:jwt-express-demo,代码行数:8,代码来源:notes.ts


注:本文中的express.Response.sendStatus方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。