Skip to content

Commit de94212

Browse files
committed
🐛 Fix: qiniu error handler
1 parent 78e9f03 commit de94212

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/plugins/uploader/qiniu.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ const handle = async (ctx: PicGo): Promise<PicGo> => {
4646
const options = postOptions(qiniuOptions, img.fileName, getToken(qiniuOptions), base64Image)
4747
const res = await ctx.Request.request(options)
4848
const body = JSON.parse(res)
49-
if (body.key) {
49+
if (body?.key) {
5050
delete img.base64Image
5151
delete img.buffer
5252
const baseUrl = qiniuOptions.url
@@ -64,11 +64,14 @@ const handle = async (ctx: PicGo): Promise<PicGo> => {
6464
return ctx
6565
} catch (err) {
6666
if (err.message !== 'Upload failed') {
67-
const error = JSON.parse(err.response.body)
68-
ctx.emit('notification', {
69-
title: '上传失败',
70-
body: error.error
71-
})
67+
// err.response maybe undefined
68+
if (err.response) {
69+
const error = JSON.parse(err.response.body || '{}')
70+
ctx.emit('notification', {
71+
title: '上传失败',
72+
body: error.error
73+
})
74+
}
7275
}
7376
throw err
7477
}

0 commit comments

Comments
 (0)