Skip to content

Commit 4f0330b

Browse files
authored
Merge pull request #1521 from input-output-hk/fix/http-provider-proxy-has
fix(cardano-services-client): comply HttpProvider with 'normal' Object behavior
2 parents bb4bba5 + 9900635 commit 4f0330b

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

packages/cardano-services-client/src/HttpProvider.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,9 @@ export const createHttpProvider = <T extends Provider>({
7878
new Proxy<T>({} as T, {
7979
// eslint-disable-next-line sonarjs/cognitive-complexity
8080
get(_, prop) {
81-
if (prop === 'then') return;
8281
const method = prop as keyof T;
8382
const urlPath = paths[method];
84-
if (!urlPath)
85-
throw new ProviderError(ProviderFailure.NotImplemented, `HttpProvider missing path for '${prop.toString()}'`);
83+
if (!urlPath) return;
8684
return async (...args: any[]) => {
8785
try {
8886
const req: AxiosRequestConfig = {
@@ -123,5 +121,9 @@ export const createHttpProvider = <T extends Provider>({
123121
throw new ProviderError(ProviderFailure.Unknown, error);
124122
}
125123
};
124+
},
125+
126+
has(_, prop) {
127+
return prop in paths;
126128
}
127129
});

packages/cardano-services-client/test/HttpProvider.test.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,16 @@ describe('createHttpProvider', () => {
6363
if (closeServer) await closeServer();
6464
});
6565

66-
it('attempting to access unimplemented method throws ProviderError', async () => {
66+
it('attempting to access unimplemented method returns undefined', async () => {
6767
const provider = createTxSubmitProviderClient();
68+
expect('doesNotExist' in provider).toBe(false);
6869
// eslint-disable-next-line @typescript-eslint/no-explicit-any
69-
expect(() => (provider as any).doesNotExist).toThrowError(ProviderError);
70+
expect((provider as any).doesNotExist).toBeUndefined();
71+
});
72+
73+
it('"in" operator for implemented property returns true', async () => {
74+
const provider = createTxSubmitProviderClient();
75+
expect('healthCheck' in provider).toBe(true);
7076
});
7177

7278
it('passes through axios options, merging custom header with the included provider version headers', async () => {

0 commit comments

Comments
 (0)