Skip to content

Commit 0fcf1dc

Browse files
committed
Fix all options not being passed to the got request library
Fixes #151
1 parent 1b3e067 commit 0fcf1dc

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import Conf from 'conf';
22
import {Options} from 'got';
33

44
export interface FetchOptions extends Options {
5+
// Deprecated, but left for backwards-compatibility.
56
/**
67
URL search parameters.
78
*/

index.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,25 +116,30 @@ alfy.fetch = async (url, options) => {
116116
...options,
117117
};
118118

119+
// Deprecated, but left for backwards-compatibility.
120+
if (options.query) {
121+
options.searchParams = options.query;
122+
}
123+
119124
if (typeof url !== 'string') {
120-
return Promise.reject(new TypeError(`Expected \`url\` to be a \`string\`, got \`${typeof url}\``));
125+
throw new TypeError(`Expected \`url\` to be a \`string\`, got \`${typeof url}\``);
121126
}
122127

123128
if (options.transform && typeof options.transform !== 'function') {
124-
return Promise.reject(new TypeError(`Expected \`transform\` to be a \`function\`, got \`${typeof options.transform}\``));
129+
throw new TypeError(`Expected \`transform\` to be a \`function\`, got \`${typeof options.transform}\``);
125130
}
126131

127132
const rawKey = url + JSON.stringify(options);
128133
const key = rawKey.replace(/\./g, '\\.');
129134
const cachedResponse = alfy.cache.get(key, {ignoreMaxAge: true});
130135

131136
if (cachedResponse && !alfy.cache.isExpired(key)) {
132-
return Promise.resolve(cachedResponse);
137+
return cachedResponse;
133138
}
134139

135140
let response;
136141
try {
137-
response = await got(url, {searchParams: options.query}).json();
142+
response = await got(url, options).json();
138143
} catch (error) {
139144
if (cachedResponse) {
140145
return cachedResponse;

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ URL to fetch.
351351

352352
Type: `object`
353353

354-
Any of the [`got` options](https://github.com/sindresorhus/got#options).
354+
Any of the [`got` options](https://github.com/sindresorhus/got/tree/v11.8.3#api) and the below options.
355355

356356
###### json
357357

0 commit comments

Comments
 (0)