Commit 1f30b9ca03fbd9516d1de540b63da546c7c9c44b
1 parent
10569b6b
Exists in
master
and in
1 other branch
增加多图上传错误处理
Showing
1 changed file
with
27 additions
and
22 deletions
Show diff stats
packages/Image-upload/multiple.vue
| ... | ... | @@ -135,6 +135,7 @@ export default { |
| 135 | 135 | default: false |
| 136 | 136 | }, |
| 137 | 137 | responseFormat: Function, |
| 138 | + errorFormat: Function, | |
| 138 | 139 | limit: { |
| 139 | 140 | type: Number, |
| 140 | 141 | default: 3 |
| ... | ... | @@ -221,28 +222,32 @@ export default { |
| 221 | 222 | } |
| 222 | 223 | }) |
| 223 | 224 | .catch(error => { |
| 224 | - const codeMessage = { | |
| 225 | - 200: '服务器成功返回请求的数据', | |
| 226 | - 201: '新建或修改数据成功。', | |
| 227 | - 202: '一个请求已经进入后台排队(异步任务)', | |
| 228 | - 204: '删除数据成功。', | |
| 229 | - 400: '发出的请求有错误,服务器没有进行新建或修改数据,的操作。', | |
| 230 | - 401: '用户没有权限(令牌、用户名、密码错误)。', | |
| 231 | - 403: '用户得到授权,但是访问是被禁止的。', | |
| 232 | - 404: '发出的请求针对的是不存在的记录,服务器没有进行操作', | |
| 233 | - 406: '请求的格式不可得。', | |
| 234 | - 410: '请求的资源被永久删除,且不会再得到的。', | |
| 235 | - 422: '当创建一个对象时,发生一个验证错误。', | |
| 236 | - 500: '服务器发生错误,请检查服务器', | |
| 237 | - 502: '网关错误', | |
| 238 | - 503: '服务不可用,服务器暂时过载或维护', | |
| 239 | - 504: '网关超时' | |
| 240 | - }; | |
| 241 | - const { response = {} } = error; | |
| 242 | - if (!(response.status >= 200 && response.status < 300)) { | |
| 243 | - const errortext = codeMessage[response.status] || response.statusText; | |
| 244 | - const messageContent = `${response.request.responseURL} ${errortext}`; | |
| 245 | - this.$notify.error({ title: `请求错误 ${response.status}:`, message: messageContent, duration: 3000 }); | |
| 225 | + if (this.errorFormat) { | |
| 226 | + this.errorFormat(error); | |
| 227 | + } else { | |
| 228 | + const codeMessage = { | |
| 229 | + 200: '服务器成功返回请求的数据', | |
| 230 | + 201: '新建或修改数据成功。', | |
| 231 | + 202: '一个请求已经进入后台排队(异步任务)', | |
| 232 | + 204: '删除数据成功。', | |
| 233 | + 400: '发出的请求有错误,服务器没有进行新建或修改数据,的操作。', | |
| 234 | + 401: '用户没有权限(令牌、用户名、密码错误)。', | |
| 235 | + 403: '用户得到授权,但是访问是被禁止的。', | |
| 236 | + 404: '发出的请求针对的是不存在的记录,服务器没有进行操作', | |
| 237 | + 406: '请求的格式不可得。', | |
| 238 | + 410: '请求的资源被永久删除,且不会再得到的。', | |
| 239 | + 422: '当创建一个对象时,发生一个验证错误。', | |
| 240 | + 500: '服务器发生错误,请检查服务器', | |
| 241 | + 502: '网关错误', | |
| 242 | + 503: '服务不可用,服务器暂时过载或维护', | |
| 243 | + 504: '网关超时' | |
| 244 | + }; | |
| 245 | + const { response = {} } = error; | |
| 246 | + if (!(response.status >= 200 && response.status < 300)) { | |
| 247 | + const errortext = codeMessage[response.status] || response.statusText; | |
| 248 | + const messageContent = `${response.request ? response.request.responseURL : ''} ${errortext}`; | |
| 249 | + this.$notify.error({ title: `请求错误 ${response.status}:`, message: messageContent, duration: 3000 }); | |
| 250 | + } | |
| 246 | 251 | } |
| 247 | 252 | }); |
| 248 | 253 | } | ... | ... |