fix(core): preserve context-specific auth error messages
Add optional context parameter to getAuthHeaders() so callers can provide feature-specific suffixes (e.g. "to use web search") in the not-logged-in error message, restoring the original behavior. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
53cffe923b
commit
882e34c491
3 changed files with 8 additions and 4 deletions
|
|
@ -22,7 +22,7 @@ export async function financeFetch<T = Record<string, unknown>>(
|
|||
params: Record<string, string | string[] | number | boolean | undefined>,
|
||||
signal?: AbortSignal,
|
||||
): Promise<{ data: T; url: string }> {
|
||||
const authHeaders = getAuthHeaders();
|
||||
const authHeaders = getAuthHeaders("to use financial data tools");
|
||||
|
||||
const url = new URL(PATH_PREFIX + path, API_BASE_URL);
|
||||
for (const [key, value] of Object.entries(params)) {
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ async function runDevvSearch(params: {
|
|||
snippet: string;
|
||||
}>;
|
||||
}> {
|
||||
const authHeaders = getAuthHeaders();
|
||||
const authHeaders = getAuthHeaders("to use web search");
|
||||
|
||||
const res = await fetch(`${API_BASE_URL}${WEB_SEARCH_PATH}`, {
|
||||
method: "POST",
|
||||
|
|
|
|||
|
|
@ -5,12 +5,16 @@ export const API_BASE_URL = "https://api-dev.copilothub.ai";
|
|||
/**
|
||||
* Return auth headers for the proxy API.
|
||||
* Throws if the user is not logged in.
|
||||
*
|
||||
* @param context - Optional feature name appended to the error message
|
||||
* (e.g. "to use web search").
|
||||
*/
|
||||
export function getAuthHeaders(): Record<string, string> {
|
||||
export function getAuthHeaders(context?: string): Record<string, string> {
|
||||
const auth = getLocalAuth();
|
||||
if (!auth) {
|
||||
const suffix = context ? ` ${context}` : "";
|
||||
throw new Error(
|
||||
"Not logged in. Please sign in via the Desktop app.",
|
||||
`Not logged in. Please sign in via the Desktop app${suffix}.`,
|
||||
);
|
||||
}
|
||||
return {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue