本文整理汇总了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);
}
});
示例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);
}
}
示例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);
};
示例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);
}
});
示例5:
productService.retrieveProduct(req.params.name).then((product: ProductInstance) => {
if (product) {
return res.send(product);
} else {
return res.sendStatus(404);
}
}).catch((error: Error) => {
示例6: ensureUser
function ensureUser(req: Request, res: Response, next: NextFunction) {
if (req.user) {
next();
} else {
res.sendStatus(401);
}
}
示例7:
}, (status, body) => {
if (body == null || body == '') {
res.sendStatus(status);
} else {
res.status(status).send(body);
}
}, next);
示例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);
}
});
示例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);
}
}
示例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);
}
});