本文整理汇总了TypeScript中@nestjs/common.ArgumentsHost类的典型用法代码示例。如果您正苦于以下问题:TypeScript ArgumentsHost类的具体用法?TypeScript ArgumentsHost怎么用?TypeScript ArgumentsHost使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ArgumentsHost类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: catch
catch(exception: HttpException, host: ArgumentsHost) {
const ctx = host.switchToHttp();
const response = ctx.getResponse();
const request = ctx.getRequest();
response.status(status).json({
statusCode: exception.getStatus(),
timestamp: new Date().toISOString(),
path: request.url,
});
}
示例2: catch
catch(exception: T, host: ArgumentsHost) {
const client = host.switchToWs().getClient();
const status = 'error';
if (!(exception instanceof WsException)) {
const errorMessage = MESSAGES.UNKNOWN_EXCEPTION_MESSAGE;
return client.emit('exception', { status, message: errorMessage });
}
const result = exception.getError();
const message = isObject(result)
? result
: {
status,
message: result,
};
client.emit('exception', message);
}
示例3: catch
catch(exception: BusinessException, host: ArgumentsHost) {
const ctx = host.switchToHttp();
const response = ctx.getResponse();
const status = exception.status;
const userMessage = exception.userMessage;
const technicalMessage = exception.technicalMessage;
console.error(technicalMessage);
response
.status(status)
.json({
success: false,
name: exception.name,
userMessage
});
}