Skip to content

Commit

Permalink
restoring errorHandling integration test file for now
Browse files Browse the repository at this point in the history
  • Loading branch information
austin-denoble committed Oct 31, 2023
1 parent beaf6f2 commit 16a0572
Showing 1 changed file with 49 additions and 14 deletions.
63 changes: 49 additions & 14 deletions src/integration/errorHandling.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,12 @@ import { PineconeConnectionError } from '../errors';
import { Pinecone } from '../index';

describe('Error handling', () => {
describe('when network error occurs', () => {
let p;
beforeEach(() => {
p = new Pinecone({
describe('when environment is wrong', () => {
test('calling control plane', async () => {
const p = new Pinecone({
apiKey: process.env.PINECONE_API_KEY || '',
fetchApi: async () => {
throw new Error('network failure');
},
});
});

test('calling control plane', async () => {
try {
await p.listIndexes();
} catch (e) {
Expand All @@ -22,23 +16,64 @@ describe('Error handling', () => {
expect(err.message).toEqual(
'Request failed to reach Pinecone. This can occur for reasons such as incorrect configuration (environment, project id, index name), network problems that prevent the request from being completed, or a Pinecone API outage. Check your client configuration, check your network connection, and visit https://status.pinecone.io/ to see whether any outages are ongoing.'
);
// @ts-ignore
expect(err.cause.name).toEqual('Error');
// @ts-ignore
expect(err.cause.message).toEqual('network failure');
expect(err.cause).toBeDefined();
}
});

test('calling data plane', async () => {
const p = new Pinecone({
apiKey: process.env.PINECONE_API_KEY || '',
});

try {
await p.index('foo-index').query({ topK: 10, id: '1' });
} catch (e) {
const err = e as PineconeConnectionError;
expect(err.name).toEqual('PineconeConnectionError');
expect(err.message).toEqual(
`Request failed to reach Pinecone while calling https://controller.${process.env.PINECONE_ENVIRONMENT}.pinecone.io/actions/whoami. This can occur for reasons such as incorrect configuration (environment, project id, index name), network problems that prevent the request from being completed, or a Pinecone API outage. Check your client configuration, check your network connection, and visit https://status.pinecone.io/ to see whether any outages are ongoing.`
'Request failed to reach Pinecone while calling https://controller.wrong-environment2.pinecone.io/actions/whoami. This can occur for reasons such as incorrect configuration (environment, project id, index name), network problems that prevent the request from being completed, or a Pinecone API outage. Check your client configuration, check your network connection, and visit https://status.pinecone.io/ to see whether any outages are ongoing.'
);
}
});

describe('when network error occurs', () => {
let p;
beforeEach(() => {
p = new Pinecone({
apiKey: process.env.PINECONE_API_KEY || '',
fetchApi: async () => {
throw new Error('network failure');
},
});
});

test('calling control plane', async () => {
try {
await p.listIndexes();
} catch (e) {
const err = e as PineconeConnectionError;
expect(err.name).toEqual('PineconeConnectionError');
expect(err.message).toEqual(
'Request failed to reach Pinecone. This can occur for reasons such as incorrect configuration (environment, project id, index name), network problems that prevent the request from being completed, or a Pinecone API outage. Check your client configuration, check your network connection, and visit https://status.pinecone.io/ to see whether any outages are ongoing.'
);
// @ts-ignore
expect(err.cause.name).toEqual('Error');
// @ts-ignore
expect(err.cause.message).toEqual('network failure');
}
});

test('calling data plane', async () => {
try {
await p.index('foo-index').query({ topK: 10, id: '1' });
} catch (e) {
const err = e as PineconeConnectionError;
expect(err.name).toEqual('PineconeConnectionError');
expect(err.message).toEqual(
`Request failed to reach Pinecone while calling https://controller.${process.env.PINECONE_ENVIRONMENT}.pinecone.io/actions/whoami. This can occur for reasons such as incorrect configuration (environment, project id, index name), network problems that prevent the request from being completed, or a Pinecone API outage. Check your client configuration, check your network connection, and visit https://status.pinecone.io/ to see whether any outages are ongoing.`
);
}
});
});
});
});

0 comments on commit 16a0572

Please sign in to comment.