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:
+1
-1
@@ -56,7 +56,7 @@ export function resolveSearchDefaults(
|
|||||||
params: { model?: string; incognito?: boolean },
|
params: { model?: string; incognito?: boolean },
|
||||||
config: PerplexityConfig,
|
config: PerplexityConfig,
|
||||||
): { model: string; incognito: boolean } {
|
): { 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 envIncognito = process.env.PI_PERPLEXITY_INCOGNITO || undefined;
|
||||||
|
|
||||||
const model = params.model
|
const model = params.model
|
||||||
|
|||||||
+6
-4
@@ -12,6 +12,7 @@ import { formatForLLM } from "./search/format.js";
|
|||||||
import { searchPerplexity } from "./search/client.js";
|
import { searchPerplexity } from "./search/client.js";
|
||||||
import { renderPerplexityCall } from "./render/call.js";
|
import { renderPerplexityCall } from "./render/call.js";
|
||||||
import { renderPerplexityResult } from "./render/result.js";
|
import { renderPerplexityResult } from "./render/result.js";
|
||||||
|
import { errorMessage } from "./render/util.js";
|
||||||
import { AuthError, SearchError } from "./search/types.js";
|
import { AuthError, SearchError } from "./search/types.js";
|
||||||
|
|
||||||
export default function (pi: ExtensionAPI) {
|
export default function (pi: ExtensionAPI) {
|
||||||
@@ -115,17 +116,18 @@ export default function (pi: ExtensionAPI) {
|
|||||||
if (error instanceof AuthError) {
|
if (error instanceof AuthError) {
|
||||||
return {
|
return {
|
||||||
content: [{ type: "text", text: `Authentication failed: ${error.message}` }],
|
content: [{ type: "text", text: `Authentication failed: ${error.message}` }],
|
||||||
details: { sourceCount, queryMs },
|
details: { sourceCount, queryMs, isError: true },
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (error instanceof SearchError) {
|
if (error instanceof SearchError) {
|
||||||
if (error.code === "AUTH") {
|
if (error.code === "AUTH") {
|
||||||
|
// Clear cached token on auth rejection so next call triggers re-login.
|
||||||
await clearToken().catch(() => undefined);
|
await clearToken().catch(() => undefined);
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
content: [{ type: "text", text: `Perplexity search failed: ${error.message}` }],
|
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: [
|
content: [
|
||||||
{
|
{
|
||||||
type: "text",
|
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 },
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user