Skip to content

Commit

Permalink
address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
0xmaayan committed Oct 24, 2023
1 parent 20bc900 commit 834d0da
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
8 changes: 4 additions & 4 deletions examples/typescript/custom_client.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Example to demostrate how one can config the SDK to use a custom client.
* Example to demonstrate how one can config the SDK to use a custom client.
*
* The SDK by default supports axios client on web environment and go client on node environment
* with http2 support.
Expand Down Expand Up @@ -37,7 +37,7 @@ export async function fetchCustomClient<Req, Res>(requestOptions: ClientRequest<
};
}

export async function superagnetCustomClient<Req, Res>(
export async function superagentCustomClient<Req, Res>(
requestOptions: ClientRequest<Req>,
): Promise<ClientResponse<Res>> {
const { params, method, url, headers, body } = requestOptions;
Expand Down Expand Up @@ -65,10 +65,10 @@ export async function superagnetCustomClient<Req, Res>(
}

const example = async () => {
console.log("This example demostrate how one can config for a custom client ot be used by the SDK");
console.log("This example demonstrate how one can config for a custom client ot be used by the SDK");

async function withSuperagentClient() {
const config = new AptosConfig({ client: { provider: superagnetCustomClient } });
const config = new AptosConfig({ client: { provider: superagentCustomClient } });
const aptos = new Aptos(config);

console.log(`\nclient being used ${config.client.provider.name}`);
Expand Down
7 changes: 4 additions & 3 deletions src/client/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,16 @@ export async function aptosRequest<Req, Res>(
// to support both fullnode and indexer responses,
// check if it is an indexer query, and adjust response.data
if (aptosConfig.isIndexerRequest(url)) {
const indexerResponse = result.data as any;
// errors from indexer
if ((result.data as any).errors) {
if (indexerResponse.errors) {
throw new AptosApiError(
options,
result,
(response.data as any).errors[0].message ?? `Unhandled Error ${response.status} : ${response.statusText}`,
indexerResponse.errors[0].message ?? `Unhandled Error ${response.status} : ${response.statusText}`,
);
}
result.data = (result.data as any).data as Res;
result.data = indexerResponse.data as Res;
}

if (result.status >= 200 && result.status < 300) {
Expand Down

0 comments on commit 834d0da

Please sign in to comment.