Skip to content

Commit

Permalink
🐛 Fix: qiniu error handler
Browse files Browse the repository at this point in the history
  • Loading branch information
Molunerfinn committed Sep 28, 2020
1 parent 78e9f03 commit de94212
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/plugins/uploader/qiniu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const handle = async (ctx: PicGo): Promise<PicGo> => {
const options = postOptions(qiniuOptions, img.fileName, getToken(qiniuOptions), base64Image)
const res = await ctx.Request.request(options)
const body = JSON.parse(res)
if (body.key) {
if (body?.key) {
delete img.base64Image
delete img.buffer
const baseUrl = qiniuOptions.url
Expand All @@ -64,11 +64,14 @@ const handle = async (ctx: PicGo): Promise<PicGo> => {
return ctx
} catch (err) {
if (err.message !== 'Upload failed') {
const error = JSON.parse(err.response.body)
ctx.emit('notification', {
title: '上传失败',
body: error.error
})
// err.response maybe undefined
if (err.response) {
const error = JSON.parse(err.response.body || '{}')
ctx.emit('notification', {
title: '上传失败',
body: error.error
})
}
}
throw err
}
Expand Down

0 comments on commit de94212

Please sign in to comment.