Skip to content

Commit cb032ea

Browse files
authored
Throw a TypeError on an invalid redirect option (node-fetch#1019)
1 parent 5c657e7 commit cb032ea

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ export default async function fetch(url, options_) {
168168
}
169169

170170
default:
171-
// Do nothing
171+
return reject(new TypeError(`Redirect option '${request.redirect}' is not a valid value of RequestRedirect`));
172172
}
173173
}
174174

test/main.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,19 @@ describe('node-fetch', () => {
524524
});
525525
});
526526

527+
it('should throw a TypeError on an invalid redirect option', () => {
528+
const url = `${base}redirect/301`;
529+
const options = {
530+
redirect: 'foobar'
531+
};
532+
return fetch(url, options).then(() => {
533+
expect.fail();
534+
}, error => {
535+
expect(error).to.be.an.instanceOf(TypeError);
536+
expect(error.message).to.equal('Redirect option \'foobar\' is not a valid value of RequestRedirect');
537+
});
538+
});
539+
527540
it('should set redirected property on response when redirect', () => {
528541
const url = `${base}redirect/301`;
529542
return fetch(url).then(res => {

0 commit comments

Comments
 (0)