我的应用程序中有两个组件。这是一个前端,这是建立在角度和后端构建使用express。我在后端使用Nest.js框架。
我有一个http-exception.filter.ts文件,它负责处理任何抛出的异常。到目前为止,我一直在以这种方式处理应用程序中的内部服务器错误。
if(exception.getStatus() === 500) {
response
.status(500)
.json({
status: '500',
code: 'INTERNAL_SERVER_ERROR',
message: 'Internal Server Error'
});
}但是,现在已经设计了一个HTML页面来显示内部服务器错误消息。要呈现该页面,我只需点击URL /ui/internal-server-error即可。所以,我试着用下面的代码来实现。
response
.status(500)
.redirect('/ui/internal-server-error');该页面在发生内部服务器错误时加载,但问题是,当我在浏览器中读取网络日志时,无法获得500状态。取而代之的是,我正在获取304 Not modified状态。
有谁能给我指个方向吗?我想要显示错误页面与状态代码500和UI页面只需要来自前端,因为我没有访问它。
发布于 2020-04-09 13:06:25
当调用redirect时,它设置状态,因此500将被替换。
从the express docs (相关,因为NestJS默认使用Express ):
Redirects to the URL derived from the specified path, with specified status, a positive integer that corresponds to an HTTP status code . If not specified, status defaults to “302 “Found”.
res.redirect('/foo/bar')
res.redirect('http://example.com')
res.redirect(301, 'http://example.com')
res.redirect('../login')将所需的状态作为参数添加到redirect。
https://stackoverflow.com/questions/61106246
复制相似问题