Skip to content

Commit a06fa0d

Browse files
authored
Throw error when constructing client without required auth parameter (#77)
1 parent fdbb5d0 commit a06fa0d

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ class Replicate {
3333
* @param {Function} [options.fetch] - Fetch function to use. Defaults to `globalThis.fetch`
3434
*/
3535
constructor(options) {
36+
if (!options.auth) {
37+
throw new Error('Missing required parameter: auth');
38+
}
39+
3640
this.auth = options.auth;
3741
this.userAgent =
3842
options.userAgent || `replicate-javascript/${packageJSON.version}`;

index.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,22 @@ describe('Replicate client', () => {
3333
});
3434
expect(clientWithCustomUserAgent.userAgent).toBe('my-app/1.2.3');
3535
});
36+
37+
test('Throws error if no auth token is provided', () => {
38+
const expected = 'Missing required parameter: auth'
39+
40+
expect(() => {
41+
new Replicate({ auth: undefined });
42+
}).toThrow(expected);
43+
44+
expect(() => {
45+
new Replicate({ auth: null });
46+
}).toThrow(expected);
47+
48+
expect(() => {
49+
new Replicate({ auth: "" });
50+
}).toThrow(expected);
51+
});
3652
});
3753

3854
describe('collections.list', () => {

0 commit comments

Comments
 (0)