Skip to content

Commit

Permalink
🐛 Fix: let tcyun error info more detail
Browse files Browse the repository at this point in the history
  • Loading branch information
Molunerfinn committed Oct 28, 2020
1 parent de94212 commit ddf645f
Showing 1 changed file with 7 additions and 17 deletions.
24 changes: 7 additions & 17 deletions src/plugins/uploader/tcyun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ const handle = async (ctx: PicGo): Promise<PicGo | boolean> => {
const res = await ctx.Request.request(options)
.then((res: any) => res)
.catch((err: Error) => {
console.log(err)
ctx.log.error(err)
return {
statusCode: 400,
body: {
Expand All @@ -120,7 +120,7 @@ const handle = async (ctx: PicGo): Promise<PicGo | boolean> => {
body = res
}
if (body.statusCode === 400) {
throw new Error('Upload failed')
throw new Error(body.msg || body.message)
}
if (useV4 && body.message === 'SUCCESS') {
delete img.base64Image
Expand All @@ -139,31 +139,21 @@ const handle = async (ctx: PicGo): Promise<PicGo | boolean> => {
img.imgUrl = `https://${tcYunOptions.bucket}.cos.${tcYunOptions.area}.myqcloud.com/${path}${img.fileName}`
}
} else {
ctx.emit('notification', {
title: '上传失败',
body: res.body.msg
})
throw new Error('Upload failed')
throw new Error(res.body.msg)
}
}
}
return ctx
} catch (err) {
if (err.message !== 'Upload failed') {
let body
if (!tcYunOptions.version || tcYunOptions.version === 'v4') {
body = JSON.parse(err.error)
if (!tcYunOptions.version || tcYunOptions.version === 'v4') {
try {
const body = JSON.parse(err.error)
ctx.emit('notification', {
title: '上传失败',
body: `错误码:${body.code as string},请打开浏览器粘贴地址查看相关原因`,
text: 'https://cloud.tencent.com/document/product/436/8432'
})
}
} else {
ctx.emit('notification', {
title: '上传失败',
body: '请检查你的配置项是否正确'
})
} catch (e) {}
}
throw err
}
Expand Down

0 comments on commit ddf645f

Please sign in to comment.