【发布时间】:2020-10-07 14:10:47
【问题描述】:
我知道 NestJS 会将所有不同于 200-299 的状态码作为错误处理,并且我已经创建了自己的 HttpExceptionFilter implements ExceptionFilter 来处理错误。
嗯,这是我目前的情况。我的一个供应商正在向我发送状态码为 500 的响应,以防某个值错误(不是真正的服务器错误),但在响应中它带有消息和描述。
有没有办法在不将响应转移到我的ExceptionFilter 的情况下捕获inline 异常?
const options = {
requestBody,
headers: {
Authorization: `Bearer 12345`,
'Content-Type': 'text/plain',
},
data: requestBody,
};
const endpoint = http://myclientendpoint.com;
try {
const response = await this.httpService
.post(endpoint, requestBody, options)
.toPromise();
if (
response == null ||
response == undefined ||
response.data == null ||
response.data == undefined
) {
return null;
}
console.log(response.data);
return await response.data;
} catch (error) {
console.log('>>> THIS IS TRIGGERED WITHOUT THE RESPONSE BODY');
console.log(error);
return null;
}
【问题讨论】:
标签: nestjs