@@ -122,9 +122,15 @@ export const resolveKyOptions = (): Options => {
122
122
}
123
123
}
124
124
125
+ function throwNoConfig ( ) : never {
126
+ throw new Error (
127
+ `API config is empty! Please call \`setApiConfig\` first.\nPlease refer to https://github.com/open-jike/jike-sdk#usage`
128
+ )
129
+ }
130
+
125
131
/** 获取 API 配置 */
126
132
export const getApiConfig = ( ) => {
127
- if ( ! apiConfig ) throw new Error ( 'Please set apiConfig!' )
133
+ if ( ! apiConfig ) throwNoConfig ( )
128
134
return apiConfig
129
135
}
130
136
@@ -142,9 +148,12 @@ let _request: KyInstance
142
148
* API 请求函数,继承自 [ky](https://github.com/sindresorhus/ky)
143
149
*/
144
150
export const request = new Proxy ( ( ) => undefined , {
145
- get : ( _o , ...args ) => Reflect . get ( _request , ...args ) ,
146
- apply : ( _o , ...args ) => Reflect . apply ( _request , ...args ) ,
147
- ownKeys : ( _o , ...args ) => Reflect . ownKeys ( _request , ...args ) ,
151
+ get : ( _ , ...args ) => {
152
+ if ( ! apiConfig ) throwNoConfig ( )
153
+ return Reflect . get ( _request , ...args )
154
+ } ,
155
+ apply : ( _ , ...args ) => Reflect . apply ( _request , ...args ) ,
156
+ ownKeys : ( _ , ...args ) => Reflect . ownKeys ( _request , ...args ) ,
148
157
} ) as unknown as KyInstance
149
158
150
159
type ResponseMeta = Pick <
0 commit comments