Skip to content

Commit 1124209

Browse files
committed
feat: throw error when no config
1 parent 88e1c36 commit 1124209

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/request.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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 配置 */
126132
export 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
*/
144150
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),
148157
}) as unknown as KyInstance
149158

150159
type ResponseMeta = Pick<

0 commit comments

Comments
 (0)