fix(search): restore error rendering and safe error handling

- Re-add isError flag to error details so renderPerplexityResult
  shows error styling instead of green success rows
- Use errorMessage() for unknown errors instead of unsafe cast
- Trim whitespace-only PI_PERPLEXITY_MODEL env var values
- Add comment explaining clearToken() on AUTH rejection
This commit is contained in:
Ivan Pereira
2026-03-21 21:28:51 +00:00
parent fcc7613edc
commit 96a3246d1e
2 changed files with 7 additions and 5 deletions
+1 -1
View File
@@ -56,7 +56,7 @@ export function resolveSearchDefaults(
params: { model?: string; incognito?: boolean },
config: PerplexityConfig,
): { model: string; incognito: boolean } {
const envModel = process.env.PI_PERPLEXITY_MODEL || undefined;
const envModel = process.env.PI_PERPLEXITY_MODEL?.trim() || undefined;
const envIncognito = process.env.PI_PERPLEXITY_INCOGNITO || undefined;
const model = params.model
+6 -4
View File
@@ -12,6 +12,7 @@ import { formatForLLM } from "./search/format.js";
import { searchPerplexity } from "./search/client.js";
import { renderPerplexityCall } from "./render/call.js";
import { renderPerplexityResult } from "./render/result.js";
import { errorMessage } from "./render/util.js";
import { AuthError, SearchError } from "./search/types.js";
export default function (pi: ExtensionAPI) {
@@ -115,17 +116,18 @@ export default function (pi: ExtensionAPI) {
if (error instanceof AuthError) {
return {
content: [{ type: "text", text: `Authentication failed: ${error.message}` }],
details: { sourceCount, queryMs },
details: { sourceCount, queryMs, isError: true },
};
}
if (error instanceof SearchError) {
if (error.code === "AUTH") {
// Clear cached token on auth rejection so next call triggers re-login.
await clearToken().catch(() => undefined);
}
return {
content: [{ type: "text", text: `Perplexity search failed: ${error.message}` }],
details: { sourceCount, queryMs },
details: { sourceCount, queryMs, isError: true },
};
}
@@ -133,10 +135,10 @@ export default function (pi: ExtensionAPI) {
content: [
{
type: "text",
text: `Perplexity search failed: ${(error as Error).message || "Unknown error"}`,
text: `Perplexity search failed: ${errorMessage(error)}`,
},
],
details: { sourceCount, queryMs },
details: { sourceCount, queryMs, isError: true },
};
}
},