Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix: throw error if missing uri or url (#239)
Co-authored-by: Justin Beckwith <justin.beckwith@gmail.com>
  • Loading branch information
jsjoeio and JustinBeckwith committed Jun 30, 2021
1 parent d50e7cd commit 4d770e3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/index.ts
Expand Up @@ -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');
Expand Down
22 changes: 22 additions & 0 deletions test/index.ts
Expand Up @@ -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();
});
});

0 comments on commit 4d770e3

Please sign in to comment.