diff --git a/src/plugins/uploader/qiniu.ts b/src/plugins/uploader/qiniu.ts index 8ba3e6c..3e4c884 100644 --- a/src/plugins/uploader/qiniu.ts +++ b/src/plugins/uploader/qiniu.ts @@ -46,7 +46,7 @@ const handle = async (ctx: PicGo): Promise => { 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 @@ -64,11 +64,14 @@ const handle = async (ctx: PicGo): Promise => { 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 }