Skip to content

Commit ddf645f

Browse files
committed
🐛 Fix: let tcyun error info more detail
1 parent de94212 commit ddf645f

File tree

1 file changed

+7
-17
lines changed

1 file changed

+7
-17
lines changed

src/plugins/uploader/tcyun.ts

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ const handle = async (ctx: PicGo): Promise<PicGo | boolean> => {
105105
const res = await ctx.Request.request(options)
106106
.then((res: any) => res)
107107
.catch((err: Error) => {
108-
console.log(err)
108+
ctx.log.error(err)
109109
return {
110110
statusCode: 400,
111111
body: {
@@ -120,7 +120,7 @@ const handle = async (ctx: PicGo): Promise<PicGo | boolean> => {
120120
body = res
121121
}
122122
if (body.statusCode === 400) {
123-
throw new Error('Upload failed')
123+
throw new Error(body.msg || body.message)
124124
}
125125
if (useV4 && body.message === 'SUCCESS') {
126126
delete img.base64Image
@@ -139,31 +139,21 @@ const handle = async (ctx: PicGo): Promise<PicGo | boolean> => {
139139
img.imgUrl = `https://${tcYunOptions.bucket}.cos.${tcYunOptions.area}.myqcloud.com/${path}${img.fileName}`
140140
}
141141
} else {
142-
ctx.emit('notification', {
143-
title: '上传失败',
144-
body: res.body.msg
145-
})
146-
throw new Error('Upload failed')
142+
throw new Error(res.body.msg)
147143
}
148144
}
149145
}
150146
return ctx
151147
} catch (err) {
152-
if (err.message !== 'Upload failed') {
153-
let body
154-
if (!tcYunOptions.version || tcYunOptions.version === 'v4') {
155-
body = JSON.parse(err.error)
148+
if (!tcYunOptions.version || tcYunOptions.version === 'v4') {
149+
try {
150+
const body = JSON.parse(err.error)
156151
ctx.emit('notification', {
157152
title: '上传失败',
158153
body: `错误码:${body.code as string},请打开浏览器粘贴地址查看相关原因`,
159154
text: 'https://cloud.tencent.com/document/product/436/8432'
160155
})
161-
}
162-
} else {
163-
ctx.emit('notification', {
164-
title: '上传失败',
165-
body: '请检查你的配置项是否正确'
166-
})
156+
} catch (e) {}
167157
}
168158
throw err
169159
}

0 commit comments

Comments
 (0)