fix: new workflow init draft failed

This commit is contained in:
AkaraChen 2024-11-13 12:59:52 +08:00
parent bc614cb507
commit f74dc032f9

View File

@ -32,11 +32,10 @@ export type ResponseError = {
const afterResponseErrorCode = (otherOptions: IOtherOptions): AfterResponseHook => { const afterResponseErrorCode = (otherOptions: IOtherOptions): AfterResponseHook => {
return async (_request, _options, response) => { return async (_request, _options, response) => {
if (!/^(2|3)\d{2}$/.test(String(response.status))) { const clonedResponse = response.clone()
const bodyJson = response.json() as Promise<ResponseError> if (!/^(2|3)\d{2}$/.test(String(clonedResponse.status))) {
switch (response.status) { const bodyJson = clonedResponse.json() as Promise<ResponseError>
case 401: switch (clonedResponse.status) {
return Promise.reject(response)
case 403: case 403:
bodyJson.then((data: ResponseError) => { bodyJson.then((data: ResponseError) => {
if (!otherOptions.silent) if (!otherOptions.silent)
@ -51,8 +50,8 @@ const afterResponseErrorCode = (otherOptions: IOtherOptions): AfterResponseHook
if (!otherOptions.silent) if (!otherOptions.silent)
Toast.notify({ type: 'error', message: data.message }) Toast.notify({ type: 'error', message: data.message })
}) })
return Promise.reject(response)
} }
throw response
} }
} }
} }
@ -98,7 +97,7 @@ const baseHooks: Hooks = {
], ],
} }
const client = ky.create({ const baseClient = ky.create({
hooks: baseHooks, hooks: baseHooks,
timeout: TIME_OUT, timeout: TIME_OUT,
}) })
@ -139,7 +138,7 @@ async function base<T>(url: string, options: FetchOptionType = {}, otherOptions:
const fetchPathname = `${base}${url.startsWith('/') ? url : `/${url}`}` const fetchPathname = `${base}${url.startsWith('/') ? url : `/${url}`}`
const res = await client.extend({ const client = baseClient.extend({
hooks: { hooks: {
...baseHooks, ...baseHooks,
beforeError: [ beforeError: [
@ -157,7 +156,10 @@ async function base<T>(url: string, options: FetchOptionType = {}, otherOptions:
afterResponseErrorCode(otherOptions), afterResponseErrorCode(otherOptions),
], ],
}, },
})(fetchPathname, { })
const res = await client(fetchPathname, {
...init,
credentials: isMarketplaceAPI credentials: isMarketplaceAPI
? 'omit' ? 'omit'
: (options.credentials || 'include'), : (options.credentials || 'include'),
@ -174,14 +176,11 @@ async function base<T>(url: string, options: FetchOptionType = {}, otherOptions:
const contentType = res.headers.get('content-type') const contentType = res.headers.get('content-type')
if ( if (
contentType contentType
&& [ContentType.download, ContentType.audio].includes(contentType) && [ContentType.download, ContentType.audio].includes(contentType)
) )
return await res.blob() as T return await res.blob() as T
return await res.json() as T return await res.json() as T
} }
export { export { base }
client,
base,
}