本文整理汇总了TypeScript中express-serve-static-core.Response.status方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Response.status方法的具体用法?TypeScript Response.status怎么用?TypeScript Response.status使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类express-serve-static-core.Response
的用法示例。
在下文中一共展示了Response.status方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: function
app.get("/news", function(request: Request, response: Response) {
if(session.isAuthenticated(request)) {
database.getNews(session.getUser(request), response);
} else {
response.status(HttpStatus.FORBIDDEN).send("");
}
});
示例2:
app.use((err: any, req: Request, res: Response) => {
res.status(err['status'] || 500);
res.render('error', {
message: err['message'],
error: {}
});
});
示例3: requireLogin
export function requireLogin(req: Request, res: Response, next) {
if (!req.session.authenticated) {
return res.status(401).json({ error: 'You must log in!' });
}
next();
};
示例4:
app.use(function(err: any, req: Request, res: Response, next: NextFunction) {
res.status(err.status || 500);
res.json({
message: err.message,
error: err
});
});
示例5:
const errorHandler = ( err: any, req: Request, res: Response, next: NextFunction ) => {
if ( this.app.get( 'env' ) === 'development' ) {
this.debugErrors( err );
this.debugErrors( req.headers );
}
res.status( err.status || 500 ).json( err );
};
示例6:
app.use((err:any, req:Request, res:Response)=>
{
res.status(err.status || 500);
res.render('error', {
content: 'sub/error',
message: err.message,
error: {}
});
});
示例7:
const errorHandler = ( err: any, req: Request, res: Response, next: NextFunction ) => {
let stack: string = '';
if ( this.app.get( 'env' ) === 'development' ) {
this.debugErrors( err );
this.debugErrors( req.headers );
stack = err.stack;
}
res.status( err.status || 500 );
res.render( 'error', {
message: err.message,
status: err.status,
stack: stack
} );
};
示例8: generalErrorHandler
export function generalErrorHandler(err: any, req: Request, res: Response, next: express.NextFunction) {
let message = `Error
method: ${ req.method }
path: ${ req.url }
payload: ${ JSON.stringify(req.body) }
`;
if (err instanceof Error) {
message += `message: ${ err.message }
stack: ${ err.stack }`;
} else {
message += `message: ${ err.toString() }`;
}
logger.error(message);
res.status(500).send({ status: 500, error: err.message || "Server error" });
}