Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix (getAgent): add nullish check for uri #239

Merged
merged 2 commits into from Jun 30, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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();
});
});