diff --git a/src/index.ts b/src/index.ts index a102f28..9956e3f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -119,6 +119,11 @@ function requestToFetchOptions(reqOpts: Options) { let uri = ((reqOpts as OptionsWithUri).uri || (reqOpts as OptionsWithUrl).url) as string; + + if (!uri) { + throw new Error('Missing uri or url in reqOpts.'); + } + if (reqOpts.useQuerystring === true || typeof reqOpts.qs === 'object') { // eslint-disable-next-line @typescript-eslint/no-var-requires const qs = require('querystring'); diff --git a/test/index.ts b/test/index.ts index 4ad9be9..ab398ff 100644 --- a/test/index.ts +++ b/test/index.ts @@ -435,4 +435,26 @@ describe('teeny', () => { } ); }); + + it('should throw an exception if uri is an empty string', done => { + assert.throws( + () => { + teenyRequest({uri: ''}); + }, + /Missing uri or url in reqOpts/, + 'Did not throw with expected message' + ); + done(); + }); + + it('should throw an exception if url is an empty string', done => { + assert.throws( + () => { + teenyRequest({url: ''}); + }, + /Missing uri or url in reqOpts/, + 'Did not throw with expected message' + ); + done(); + }); });