Skip to content

Commit f44ef43

Browse files
authoredJul 24, 2024
Fix handling of invalid arguments (#2367)
1 parent bc17e81 commit f44ef43

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed
 

Diff for: ‎source/create.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ const create = (defaults: InstanceDefaults): Got => {
5454
const lastHandler = (normalized: Options): GotReturn => {
5555
// Note: `options` is `undefined` when `new Options(...)` fails
5656
request.options = normalized;
57-
request._noPipe = !normalized.isStream;
57+
request._noPipe = !normalized?.isStream;
5858
void request.flush();
5959

60-
if (normalized.isStream) {
60+
if (normalized?.isStream) {
6161
return request;
6262
}
6363

@@ -72,7 +72,7 @@ const create = (defaults: InstanceDefaults): Got => {
7272

7373
const result = handler(newOptions, iterateHandlers) as GotReturn;
7474

75-
if (is.promise(result) && !request.options.isStream) {
75+
if (is.promise(result) && !request.options?.isStream) {
7676
promise ||= asPromise(request);
7777

7878
if (result !== promise) {

Diff for: ‎test/arguments.ts

+10
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,16 @@ test('throws if the url option is missing', async t => {
4242
});
4343
});
4444

45+
test('throws if an invalid argument is passed', async t => {
46+
await t.throwsAsync(
47+
// @ts-expect-error Error tests
48+
got(false),
49+
{
50+
instanceOf: RequestError,
51+
message: 'Expected values which are `string`, `URL`, `Object`, or `undefined`. Received values of type `boolean`.',
52+
});
53+
});
54+
4555
test('throws an error if the protocol is not specified', async t => {
4656
const error = await t.throwsAsync(got('example.com'));
4757
invalidUrl(t, error!, 'example.com');

0 commit comments

Comments
 (0)
Please sign in to comment.