找不到搜索结果时如何修复获取状态 500?
How to fix getting status 500 when search result are not found?
我的 Angular 前端设计中有搜索栏,我的后端使用 NestJS。每当我在搜索栏中输入乱码时,我的网络响应都会收到状态 500 错误。
它不应该抛出错误,我想弄清楚为什么我的查询出错只是因为无法找到一个值但不知道在哪里修复它所以,我真的如果您有机会通过查看代码来帮助我,我将不胜感激。
我做到了,像这样尝试 catch 和 thrownoException 但现在它把每个错误都视为未找到。我只是想找出为什么当我每次查询都找不到结果时它说错误并修复它。
try {
var finalSqlResults = await finalSql.getManyAndCount();
} catch (error) {
const result = { pageIndex: 0,
pageSize: 0,
results:[],
totalCount:0}
throw new NotFoundException(result);
}
您共享的更新代码片段似乎是 return从您的服务中获取 NotFoundException。而如果我们试图在这里处理错误,我们应该 return 新创建的结果 const.
try {
var finalSqlResults = await finalSql.getManyAndCount();
} catch (error) {
const result = { pageIndex: 0,
pageSize: 0,
results:[],
totalCount:0}
return result;
}
也在您分享的 Stackblitz 中。 IN 查询可能被创建为空白“()”,这可能导致抛出 500 内部服务器错误。
if (tags && tags.length > 0) {
workspaceQuery = workspaceQuery.andWhere(
new Brackets(qb => {
qb.where('wstags.tag IN(:...tags)', { tags }).orWhere(
'ctags.tag IN(:...tags)',
{ tags }
);
})
);
}
}
希望对您有所帮助!
我的 Angular 前端设计中有搜索栏,我的后端使用 NestJS。每当我在搜索栏中输入乱码时,我的网络响应都会收到状态 500 错误。
它不应该抛出错误,我想弄清楚为什么我的查询出错只是因为无法找到一个值但不知道在哪里修复它所以,我真的如果您有机会通过查看代码来帮助我,我将不胜感激。
我做到了,像这样尝试 catch 和 thrownoException 但现在它把每个错误都视为未找到。我只是想找出为什么当我每次查询都找不到结果时它说错误并修复它。
try {
var finalSqlResults = await finalSql.getManyAndCount();
} catch (error) {
const result = { pageIndex: 0,
pageSize: 0,
results:[],
totalCount:0}
throw new NotFoundException(result);
}
您共享的更新代码片段似乎是 return从您的服务中获取 NotFoundException。而如果我们试图在这里处理错误,我们应该 return 新创建的结果 const.
try {
var finalSqlResults = await finalSql.getManyAndCount();
} catch (error) {
const result = { pageIndex: 0,
pageSize: 0,
results:[],
totalCount:0}
return result;
}
也在您分享的 Stackblitz 中。 IN 查询可能被创建为空白“()”,这可能导致抛出 500 内部服务器错误。
if (tags && tags.length > 0) {
workspaceQuery = workspaceQuery.andWhere(
new Brackets(qb => {
qb.where('wstags.tag IN(:...tags)', { tags }).orWhere(
'ctags.tag IN(:...tags)',
{ tags }
);
})
);
}
}
希望对您有所帮助!