Skip to content

Commit

Permalink
chore: Update package version to 1.0.7 and improve error handling in …
Browse files Browse the repository at this point in the history
…AnalyticsEngine class
  • Loading branch information
Digital39999 committed Sep 8, 2024
1 parent 9d60498 commit fc4c88d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/nodejs/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.0.6",
"version": "1.0.7",
"name": "analytics-engine-js",
"author": "Digital39999",
"scripts": {
Expand Down
10 changes: 4 additions & 6 deletions packages/nodejs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,17 @@ export default class AnalyticsEngine {
const instanceUrl = new URL(url);
if (!instanceUrl.hostname) throw new Error('Invalid instance URL.');

const response = await axios<string>({ url, method: 'GET' }).catch((err: AxiosError<string>) => err.response);
if (!response || response.status !== 200) throw new Error('Invalid instance URL.');
else if ('error' in response && typeof response.error === 'string') throw new Error(response.error);

return;
const response = await axios.get(url).then((res) => res.data).catch((err: AxiosError) => err.response?.data);
if (response?.status !== 200) throw new Error('Invalid instance URL.');
else if ('error' in response) throw new Error(response.error);
}

private async parseAxiosRequest<T>(response: Promise<AxiosResponse<ResponseType<T>>>): Promise<T> {
const data = await response.then((res) => res.data).catch((err: AxiosError<ResponseType<T>>) => err.response?.data);

if (!data) throw new Error('Request failed.');
else if ('error' in data) throw new Error(data.error);
else if (!data.data) throw new Error('Invalid response data.');
else if (data.status !== 200) throw new Error('Request failed.');

return data.data;
}
Expand Down

0 comments on commit fc4c88d

Please sign in to comment.