@@ -122,9 +122,15 @@ export const resolveKyOptions = (): Options => {
122122 }
123123}
124124
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+
125131/** 获取 API 配置 */
126132export const getApiConfig = ( ) => {
127- if ( ! apiConfig ) throw new Error ( 'Please set apiConfig!' )
133+ if ( ! apiConfig ) throwNoConfig ( )
128134 return apiConfig
129135}
130136
@@ -142,9 +148,12 @@ let _request: KyInstance
142148 * API 请求函数,继承自 [ky](https://github.com/sindresorhus/ky)
143149 */
144150export 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 ) ,
148157} ) as unknown as KyInstance
149158
150159type ResponseMeta = Pick <
0 commit comments