misc.search: better error handling
This commit is contained in:
parent
92e803b9bb
commit
5c7abc26aa
1 changed files with 34 additions and 22 deletions
|
@ -574,10 +574,18 @@ search.callback = async function (msg, line, args, {results = 2}) {
|
|||
(res) => res.json()
|
||||
);
|
||||
delete res.results_source;
|
||||
if (res.error?.message) {
|
||||
if (res.error.message.indexOf("No results found.") > -1) {
|
||||
return "Search returned no results.";
|
||||
} else {
|
||||
return `Search returned error:\n\`\`\`\n${res.error.message}\`\`\``;
|
||||
}
|
||||
} else {
|
||||
const searchResults = Object.values(res)
|
||||
.filter((result) => !("did_you_mean" in result))
|
||||
.splice(0, Number(results));
|
||||
|
||||
if (searchResults.length > 0) {
|
||||
let out = `__**Results for \`${safeString(query)}\`**__\n`;
|
||||
for (const result of searchResults) {
|
||||
if (result.special_response) {
|
||||
|
@ -599,6 +607,10 @@ search.callback = async function (msg, line, args, {results = 2}) {
|
|||
}
|
||||
|
||||
return out.trim();
|
||||
} else {
|
||||
return "Search returned no results.";
|
||||
}
|
||||
}
|
||||
};
|
||||
hf.registerCommand(search);
|
||||
|
||||
|
|
Loading…
Reference in a new issue