File tree Expand file tree Collapse file tree 3 files changed +11
-5
lines changed Expand file tree Collapse file tree 3 files changed +11
-5
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import Conf from 'conf';
2
2
import { Options } from 'got' ;
3
3
4
4
export interface FetchOptions extends Options {
5
+ // Deprecated, but left for backwards-compatibility.
5
6
/**
6
7
URL search parameters.
7
8
*/
Original file line number Diff line number Diff line change @@ -116,25 +116,30 @@ alfy.fetch = async (url, options) => {
116
116
...options ,
117
117
} ;
118
118
119
+ // Deprecated, but left for backwards-compatibility.
120
+ if ( options . query ) {
121
+ options . searchParams = options . query ;
122
+ }
123
+
119
124
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 } \`` ) ;
121
126
}
122
127
123
128
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 } \`` ) ;
125
130
}
126
131
127
132
const rawKey = url + JSON . stringify ( options ) ;
128
133
const key = rawKey . replace ( / \. / g, '\\.' ) ;
129
134
const cachedResponse = alfy . cache . get ( key , { ignoreMaxAge : true } ) ;
130
135
131
136
if ( cachedResponse && ! alfy . cache . isExpired ( key ) ) {
132
- return Promise . resolve ( cachedResponse ) ;
137
+ return cachedResponse ;
133
138
}
134
139
135
140
let response ;
136
141
try {
137
- response = await got ( url , { searchParams : options . query } ) . json ( ) ;
142
+ response = await got ( url , options ) . json ( ) ;
138
143
} catch ( error ) {
139
144
if ( cachedResponse ) {
140
145
return cachedResponse ;
Original file line number Diff line number Diff line change @@ -351,7 +351,7 @@ URL to fetch.
351
351
352
352
Type: ` object `
353
353
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 .
355
355
356
356
###### json
357
357
You can’t perform that action at this time.
0 commit comments