refactor(sdk): musicSdk 全量迁移至 TypeScript
This commit is contained in:
1 parent
f289df4cd7
commit
1dfb7a59ca
83 files changed
+924
-732
No files matched your search
@@ -0,0 +1,30 @@
|
||||
import { httpFetch } from '../../request.ts'
|
||||
import type { HttpOptions } from '../../types.ts'
|
||||
|
||||
/**
|
||||
* 创建一个适用于MG的Http请求
|
||||
* @param {*} url
|
||||
* @param {*} options
|
||||
* @param {*} retryNum
|
||||
*/
|
||||
export const createHttpFetch = async(url: string, options?: HttpOptions, retryNum = 0): Promise<any> => {
|
||||
if (retryNum > 2) throw new Error('try max num')
|
||||
let result
|
||||
try {
|
||||
result = await httpFetch(url, options).promise
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
return createHttpFetch(url, options, ++retryNum)
|
||||
}
|
||||
if (result.statusCode !== 200 ||
|
||||
(
|
||||
(result.body.code !== undefined
|
||||
? result.body.code
|
||||
: result.body.returnCode !== undefined
|
||||
? result.body.returnCode
|
||||
: result.body.code
|
||||
) !== '000000')
|
||||
) return createHttpFetch(url, options, ++retryNum)
|
||||
if (result.body.data) return result.body.data
|
||||
return result.body
|
||||
}
|
||||
Reference in new issue
Block a user