本文整理匯總了TypeScript中express.Response.status方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Response.status方法的具體用法?TypeScript Response.status怎麽用?TypeScript Response.status使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類express.Response
的用法示例。
在下文中一共展示了Response.status方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1:
}).catch((err)=>{
res.status(500).json({
"status":"error"
});
});
示例2: Subject
router.post("/", (req: Request, res: Response, next: NextFunction) => {
console.log("create new subject");
if (!/admin|teacher/i.test(req.authenticatedUser.rights)) {
return res.sendStatus(401);
}
// Check body
if (!req.body.code || !req.body.name) {
res.status(403); // Conflict
res.json("Code or name not set");
return;
}
let subject = new Subject(req.body);
subject.save((err) => {
if (!err) {
res.status(201); // Created
res.json(subject);
let users: {
user: string,
subject: string,
role: string
}[] = req.body.users || [];
// Add only if user is teacher
let userFound = /admin/i.test(req.authenticatedUser.rights);
for (let u of users) {
u.subject = subject._id;
// Check if user is added
if (!userFound && String(u.user) === String(req.authenticatedUser._id)) {
u.role = "Teacher";
userFound = true;
}
}
// Add teacher of not already added
if (!userFound) {
users.push({
user: req.authenticatedUser._id,
subject: subject._id,
role: "Teacher"
});
}
for (let user of req.body.users || []) {
user.user = user._id;
user.subject = subject._id;
UserSubject.findOneAndUpdate({
user: user.user,
subject: user.subject
}, {
role: user.role
}, {
upsert: true
}).exec().then((u) => {
}, (err) => {
console.log(err);
});
}
QueueSocket.createNamespace(subject.code);
} else {
res.status(409).json({errmsg: "Code is alredy registered on another subject."});
}
});
});
示例3: validateFailed
function validateFailed(res: Response, err: ErrorMessage, status: number = 400) {
res.status(status).json(err);
}
示例4:
}, err => {
winston.error('Couldn\'t find user at login.', err.message);
reporter.handleError(err);
return Promise.resolve(res.status(400).json(message));
});
示例5:
}, (dbError) => {
res.status(400).send(dbError);
});
示例6: function
}, function (err) {
log.error(err);
res.status(RestStatusCodes.ServerError).send('Server Error');
});
示例7:
.catch(err => {
winston.error('Error in getCustomCategories', { path: 'getCustomCategories', data: { error: err } })
res.status(500).json(err);
});
示例8: error
private static error(code: number, msg: string, res: Response) {
console.log(msg);
return res.status(code).send(msg);
}
示例9: function
handleError: function (res: Response, error: any): void {
res.status(500).json({message: error.message});
}