From dfef414edb0193e70d54b9558281e8dd7d0741e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0t=C4=9Bp=C3=A1n=20Gran=C3=A1t?= Date: Mon, 24 Feb 2025 14:31:09 +0100 Subject: [PATCH] fix: improve invalid api key error (#158) --- src/client/ApiClient.ts | 3 +++ src/client/getApiKeyInformation.ts | 8 ++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/client/ApiClient.ts b/src/client/ApiClient.ts index 629740da..41cb7799 100644 --- a/src/client/ApiClient.ts +++ b/src/client/ApiClient.ts @@ -99,6 +99,9 @@ export function createApiClient({ getApiKeyInfo() { return getApiKeyInformation(apiClient, apiKey!); }, + getSettings(): ApiClientProps { + return { baseUrl, apiKey, projectId, autoThrow }; + }, }; } diff --git a/src/client/getApiKeyInformation.ts b/src/client/getApiKeyInformation.ts index 37477ad2..ca37118c 100644 --- a/src/client/getApiKeyInformation.ts +++ b/src/client/getApiKeyInformation.ts @@ -34,7 +34,9 @@ export const getApiKeyInformation = async ( if (key.startsWith(API_KEY_PAK_PREFIX)) { const loadable = await client.GET('/v2/api-keys/current'); if (loadable.response.status === 401) { - exitWithError("Couldn't log in: the API key you provided is invalid."); + exitWithError( + `Couldn't log in: the API key you provided is invalid (${new URL(loadable.response.url).host}).` + ); } handleLoadableError(loadable); @@ -54,7 +56,9 @@ export const getApiKeyInformation = async ( } else { const loadable = await client.GET('/v2/pats/current'); if (loadable.response.status === 401) { - exitWithError("Couldn't log in: the API key you provided is invalid."); + exitWithError( + `Couldn't log in: the API key you provided is invalid (${new URL(loadable.response.url).host}).` + ); } handleLoadableError(loadable);