@@ -105,7 +105,7 @@ const handle = async (ctx: PicGo): Promise<PicGo | boolean> => {
105
105
const res = await ctx . Request . request ( options )
106
106
. then ( ( res : any ) => res )
107
107
. catch ( ( err : Error ) => {
108
- console . log ( err )
108
+ ctx . log . error ( err )
109
109
return {
110
110
statusCode : 400 ,
111
111
body : {
@@ -120,7 +120,7 @@ const handle = async (ctx: PicGo): Promise<PicGo | boolean> => {
120
120
body = res
121
121
}
122
122
if ( body . statusCode === 400 ) {
123
- throw new Error ( 'Upload failed' )
123
+ throw new Error ( body . msg || body . message )
124
124
}
125
125
if ( useV4 && body . message === 'SUCCESS' ) {
126
126
delete img . base64Image
@@ -139,31 +139,21 @@ const handle = async (ctx: PicGo): Promise<PicGo | boolean> => {
139
139
img . imgUrl = `https://${ tcYunOptions . bucket } .cos.${ tcYunOptions . area } .myqcloud.com/${ path } ${ img . fileName } `
140
140
}
141
141
} 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 )
147
143
}
148
144
}
149
145
}
150
146
return ctx
151
147
} 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 )
156
151
ctx . emit ( 'notification' , {
157
152
title : '上传失败' ,
158
153
body : `错误码:${ body . code as string } ,请打开浏览器粘贴地址查看相关原因` ,
159
154
text : 'https://cloud.tencent.com/document/product/436/8432'
160
155
} )
161
- }
162
- } else {
163
- ctx . emit ( 'notification' , {
164
- title : '上传失败' ,
165
- body : '请检查你的配置项是否正确'
166
- } )
156
+ } catch ( e ) { }
167
157
}
168
158
throw err
169
159
}
0 commit comments