Skip to content

Commit

Permalink
Log warning instead of throw when constructing Substrate, improve req…
Browse files Browse the repository at this point in the history
…uest error (#57)
  • Loading branch information
liamgriffiths authored Apr 10, 2024
1 parent 5109849 commit 1b72f33
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/Substrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type Configuration = {
/**
* [docs/authentication](https://docs.substrate.run/#authentication)
*/
apiKey?: string | undefined;
apiKey: string | undefined;

/**
* [docs/versioning](https://docs.substrate.run/versioning)
Expand All @@ -33,7 +33,7 @@ type Configuration = {
* [docs/introduction](https://docs.substrate.run)
*/
export class Substrate {
apiKey: string;
apiKey: string | undefined;
baseUrl: string;
apiVersion: string;
timeout: number;
Expand All @@ -50,8 +50,8 @@ export class Substrate {
backend,
}: Configuration) {
if (!apiKey) {
throw new SubstrateError(
"An API Key is required. Specify it when constructing the Substrate client: `new Substrate({ apiKey: 'API_KEY' })`",
console.warn(
"[Substrate] An API Key is required. Specify it when constructing the client: `new Substrate({ apiKey: 'API_KEY' })`",
);
}
this.apiKey = apiKey;
Expand Down Expand Up @@ -83,6 +83,10 @@ export class Substrate {
for (let node of nodes) node.response = res;

return res;
} else {
throw new SubstrateError(
`Request failed: ${apiResponse.status} ${apiResponse.statusText}`,
);
}
} catch (err: unknown) {
if (err instanceof Error) {
Expand All @@ -98,8 +102,6 @@ export class Substrate {
} finally {
clearTimeout(timeout);
}

throw new SubstrateError("Request failed");
}

/**
Expand Down

0 comments on commit 1b72f33

Please sign in to comment.