Skip to content

Commit

Permalink
fix: improve invalid api key error (#158)
Browse files Browse the repository at this point in the history
  • Loading branch information
stepan662 authored Feb 24, 2025
1 parent c3f5fad commit dfef414
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/client/ApiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ export function createApiClient({
getApiKeyInfo() {
return getApiKeyInformation(apiClient, apiKey!);
},
getSettings(): ApiClientProps {
return { baseUrl, apiKey, projectId, autoThrow };
},
};
}

Expand Down
8 changes: 6 additions & 2 deletions src/client/getApiKeyInformation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);

Expand Down

0 comments on commit dfef414

Please sign in to comment.