Skip to content

Commit 2dac011

Browse files
committed
修改容错
1 parent 1bedb79 commit 2dac011

File tree

4 files changed

+66
-52
lines changed

4 files changed

+66
-52
lines changed

dist/cos-js-sdk-v5.js

+32-25
Original file line numberDiff line numberDiff line change
@@ -1679,15 +1679,16 @@ function getBucket(params, callback) {
16791679
if (err) {
16801680
return callback(err);
16811681
}
1682-
var contents = data.ListBucketResult.Contents || [];
1683-
var CommonPrefixes = data.ListBucketResult.CommonPrefixes || [];
1682+
var ListBucketResult = data.ListBucketResult || {};
1683+
var Contents = ListBucketResult.Contents || [];
1684+
var CommonPrefixes = ListBucketResult.CommonPrefixes || [];
16841685

1685-
contents = util.isArray(contents) ? contents : [contents];
1686+
Contents = util.isArray(Contents) ? Contents : [Contents];
16861687
CommonPrefixes = util.isArray(CommonPrefixes) ? CommonPrefixes : [CommonPrefixes];
16871688

1688-
var result = util.clone(data.ListBucketResult);
1689+
var result = util.clone(ListBucketResult);
16891690
util.extend(result, {
1690-
Contents: contents,
1691+
Contents: Contents,
16911692
CommonPrefixes: CommonPrefixes,
16921693
statusCode: data.statusCode,
16931694
headers: data.headers
@@ -1747,10 +1748,11 @@ function getBucketAcl(params, callback) {
17471748
if (err) {
17481749
return callback(err);
17491750
}
1750-
var Owner = data.AccessControlPolicy.Owner || {};
1751-
var Grant = data.AccessControlPolicy.AccessControlList.Grant || [];
1751+
var AccessControlPolicy = data.AccessControlPolicy || {};
1752+
var Owner = AccessControlPolicy.Owner || {};
1753+
var Grant = AccessControlPolicy.AccessControlList.Grant || [];
17521754
Grant = util.isArray(Grant) ? Grant : [Grant];
1753-
var result = decodeAcl(data.AccessControlPolicy);
1755+
var result = decodeAcl(AccessControlPolicy);
17541756
if (data.headers && data.headers['x-cos-acl']) {
17551757
result.ACL = data.headers['x-cos-acl'];
17561758
}
@@ -2423,12 +2425,13 @@ function listObjectVersions(params, callback) {
24232425
if (err) {
24242426
return callback(err);
24252427
}
2426-
var DeleteMarkers = data.ListVersionsResult.DeleteMarker || [];
2428+
var ListVersionsResult = data.ListVersionsResult || {};
2429+
var DeleteMarkers = ListVersionsResult.DeleteMarker || [];
24272430
DeleteMarkers = util.isArray(DeleteMarkers) ? DeleteMarkers : [DeleteMarkers];
2428-
var Versions = data.ListVersionsResult.Version || [];
2431+
var Versions = ListVersionsResult.Version || [];
24292432
Versions = util.isArray(Versions) ? Versions : [Versions];
24302433

2431-
var result = util.clone(data.ListVersionsResult);
2434+
var result = util.clone(ListVersionsResult);
24322435
delete result.DeleteMarker;
24332436
delete result.Version;
24342437
util.extend(result, {
@@ -2655,10 +2658,11 @@ function getObjectAcl(params, callback) {
26552658
if (err) {
26562659
return callback(err);
26572660
}
2658-
var Owner = data.AccessControlPolicy.Owner || {};
2659-
var Grant = data.AccessControlPolicy.AccessControlList.Grant || [];
2661+
var AccessControlPolicy = data.AccessControlPolicy || {};
2662+
var Owner = AccessControlPolicy.Owner || {};
2663+
var Grant = AccessControlPolicy.AccessControlList && AccessControlPolicy.AccessControlList.Grant || [];
26602664
Grant = util.isArray(Grant) ? Grant : [Grant];
2661-
var result = decodeAcl(data.AccessControlPolicy);
2665+
var result = decodeAcl(AccessControlPolicy);
26622666
if (data.headers && data.headers['x-cos-acl']) {
26632667
result.ACL = data.headers['x-cos-acl'];
26642668
}
@@ -2743,7 +2747,7 @@ function optionsObject(params, callback) {
27432747
headers: headers
27442748
}, function (err, data) {
27452749
if (err) {
2746-
if (err.statusCode && err.statusCode == 403) {
2750+
if (err.statusCode && err.statusCode === 403) {
27472751
return callback(null, {
27482752
OptionsForbidden: true,
27492753
statusCode: err.statusCode
@@ -2804,7 +2808,7 @@ function putObjectCopy(params, callback) {
28042808
if (err) {
28052809
return callback(err);
28062810
}
2807-
var result = util.clone(data.CopyObjectResult);
2811+
var result = util.clone(data.CopyObjectResult || {});
28082812
util.extend(result, {
28092813
statusCode: data.statusCode,
28102814
headers: data.headers
@@ -2827,7 +2831,7 @@ function uploadPartCopy(params, callback) {
28272831
if (err) {
28282832
return callback(err);
28292833
}
2830-
var result = util.clone(data.CopyObjectResult);
2834+
var result = util.clone(data.CopyObjectResult || {});
28312835
util.extend(result, {
28322836
statusCode: data.statusCode,
28332837
headers: data.headers
@@ -2857,13 +2861,14 @@ function deleteMultipleObject(params, callback) {
28572861
if (err) {
28582862
return callback(err);
28592863
}
2860-
var Deleted = data.DeleteResult.Deleted || [];
2861-
var Errors = data.DeleteResult.Error || [];
2864+
var DeleteResult = data.DeleteResult || {};
2865+
var Deleted = DeleteResult.Deleted || [];
2866+
var Errors = DeleteResult.Error || [];
28622867

28632868
Deleted = util.isArray(Deleted) ? Deleted : [Deleted];
28642869
Errors = util.isArray(Errors) ? Errors : [Errors];
28652870

2866-
var result = util.clone(data.DeleteResult);
2871+
var result = util.clone(DeleteResult);
28672872
util.extend(result, {
28682873
Error: Errors,
28692874
Deleted: Deleted,
@@ -3050,7 +3055,8 @@ function multipartComplete(params, callback) {
30503055
object: params.Key,
30513056
isLocation: true
30523057
});
3053-
var result = util.extend(data.CompleteMultipartUploadResult, {
3058+
var CompleteMultipartUploadResult = data.CompleteMultipartUploadResult || {};
3059+
var result = util.extend(CompleteMultipartUploadResult, {
30543060
Location: url,
30553061
statusCode: data.statusCode,
30563062
headers: data.headers
@@ -3111,7 +3117,7 @@ function multipartList(params, callback) {
31113117
data.ListMultipartUploadsResult.Upload = Upload;
31123118
data.ListMultipartUploadsResult.CommonPrefixes = CommonPrefixes;
31133119
}
3114-
var result = util.clone(data.ListMultipartUploadsResult);
3120+
var result = util.clone(data.ListMultipartUploadsResult || {});
31153121
util.extend(result, {
31163122
statusCode: data.statusCode,
31173123
headers: data.headers
@@ -3154,11 +3160,12 @@ function multipartListPart(params, callback) {
31543160
if (err) {
31553161
return callback(err);
31563162
}
3157-
var Part = data.ListPartsResult.Part || [];
3163+
var ListPartsResult = data.ListPartsResult || {};
3164+
var Part = ListPartsResult.Part || [];
31583165
Part = util.isArray(Part) ? Part : [Part];
31593166

3160-
data.ListPartsResult.Part = Part;
3161-
var result = util.clone(data.ListPartsResult);
3167+
ListPartsResult.Part = Part;
3168+
var result = util.clone(ListPartsResult);
31623169
util.extend(result, {
31633170
statusCode: data.statusCode,
31643171
headers: data.headers

dist/cos-js-sdk-v5.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cos-js-sdk-v5",
3-
"version": "0.3.10",
3+
"version": "0.3.11",
44
"description": "cos js sdk v5",
55
"main": "index.js",
66
"scripts": {

src/base.js

+32-25
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,16 @@ function getBucket(params, callback) {
6060
if (err) {
6161
return callback(err);
6262
}
63-
var contents = data.ListBucketResult.Contents || [];
64-
var CommonPrefixes = data.ListBucketResult.CommonPrefixes || [];
63+
var ListBucketResult = data.ListBucketResult || {};
64+
var Contents = ListBucketResult.Contents || [];
65+
var CommonPrefixes = ListBucketResult.CommonPrefixes || [];
6566

66-
contents = util.isArray(contents) ? contents : [contents];
67+
Contents = util.isArray(Contents) ? Contents : [Contents];
6768
CommonPrefixes = util.isArray(CommonPrefixes) ? CommonPrefixes : [CommonPrefixes];
6869

69-
var result = util.clone(data.ListBucketResult);
70+
var result = util.clone(ListBucketResult);
7071
util.extend(result, {
71-
Contents: contents,
72+
Contents: Contents,
7273
CommonPrefixes: CommonPrefixes,
7374
statusCode: data.statusCode,
7475
headers: data.headers,
@@ -128,10 +129,11 @@ function getBucketAcl(params, callback) {
128129
if (err) {
129130
return callback(err);
130131
}
131-
var Owner = data.AccessControlPolicy.Owner || {};
132-
var Grant = data.AccessControlPolicy.AccessControlList.Grant || [];
132+
var AccessControlPolicy = data.AccessControlPolicy || {};
133+
var Owner = AccessControlPolicy.Owner || {};
134+
var Grant = AccessControlPolicy.AccessControlList.Grant || [];
133135
Grant = util.isArray(Grant) ? Grant : [Grant];
134-
var result = decodeAcl(data.AccessControlPolicy);
136+
var result = decodeAcl(AccessControlPolicy);
135137
if (data.headers && data.headers['x-cos-acl']) {
136138
result.ACL = data.headers['x-cos-acl'];
137139
}
@@ -809,12 +811,13 @@ function listObjectVersions(params, callback) {
809811
if (err) {
810812
return callback(err);
811813
}
812-
var DeleteMarkers = data.ListVersionsResult.DeleteMarker || [];
814+
var ListVersionsResult = data.ListVersionsResult || {};
815+
var DeleteMarkers = ListVersionsResult.DeleteMarker || [];
813816
DeleteMarkers = util.isArray(DeleteMarkers) ? DeleteMarkers : [DeleteMarkers];
814-
var Versions = data.ListVersionsResult.Version || [];
817+
var Versions = ListVersionsResult.Version || [];
815818
Versions = util.isArray(Versions) ? Versions : [Versions];
816819

817-
var result = util.clone(data.ListVersionsResult);
820+
var result = util.clone(ListVersionsResult);
818821
delete result.DeleteMarker;
819822
delete result.Version;
820823
util.extend(result, {
@@ -1039,10 +1042,11 @@ function getObjectAcl(params, callback) {
10391042
if (err) {
10401043
return callback(err);
10411044
}
1042-
var Owner = data.AccessControlPolicy.Owner || {};
1043-
var Grant = data.AccessControlPolicy.AccessControlList.Grant || [];
1045+
var AccessControlPolicy = data.AccessControlPolicy || {};
1046+
var Owner = AccessControlPolicy.Owner || {};
1047+
var Grant = AccessControlPolicy.AccessControlList && AccessControlPolicy.AccessControlList.Grant || [];
10441048
Grant = util.isArray(Grant) ? Grant : [Grant];
1045-
var result = decodeAcl(data.AccessControlPolicy);
1049+
var result = decodeAcl(AccessControlPolicy);
10461050
if (data.headers && data.headers['x-cos-acl']) {
10471051
result.ACL = data.headers['x-cos-acl'];
10481052
}
@@ -1127,7 +1131,7 @@ function optionsObject(params, callback) {
11271131
headers: headers,
11281132
}, function (err, data) {
11291133
if (err) {
1130-
if (err.statusCode && err.statusCode == 403) {
1134+
if (err.statusCode && err.statusCode === 403) {
11311135
return callback(null, {
11321136
OptionsForbidden: true,
11331137
statusCode: err.statusCode
@@ -1188,7 +1192,7 @@ function putObjectCopy(params, callback) {
11881192
if (err) {
11891193
return callback(err);
11901194
}
1191-
var result = util.clone(data.CopyObjectResult);
1195+
var result = util.clone(data.CopyObjectResult || {});
11921196
util.extend(result, {
11931197
statusCode: data.statusCode,
11941198
headers: data.headers,
@@ -1211,7 +1215,7 @@ function uploadPartCopy(params, callback) {
12111215
if (err) {
12121216
return callback(err);
12131217
}
1214-
var result = util.clone(data.CopyObjectResult);
1218+
var result = util.clone(data.CopyObjectResult || {});
12151219
util.extend(result, {
12161220
statusCode: data.statusCode,
12171221
headers: data.headers,
@@ -1241,13 +1245,14 @@ function deleteMultipleObject(params, callback) {
12411245
if (err) {
12421246
return callback(err);
12431247
}
1244-
var Deleted = data.DeleteResult.Deleted || [];
1245-
var Errors = data.DeleteResult.Error || [];
1248+
var DeleteResult = data.DeleteResult || {};
1249+
var Deleted = DeleteResult.Deleted || [];
1250+
var Errors = DeleteResult.Error || [];
12461251

12471252
Deleted = util.isArray(Deleted) ? Deleted : [Deleted];
12481253
Errors = util.isArray(Errors) ? Errors : [Errors];
12491254

1250-
var result = util.clone(data.DeleteResult);
1255+
var result = util.clone(DeleteResult);
12511256
util.extend(result, {
12521257
Error: Errors,
12531258
Deleted: Deleted,
@@ -1436,7 +1441,8 @@ function multipartComplete(params, callback) {
14361441
object: params.Key,
14371442
isLocation: true,
14381443
});
1439-
var result = util.extend(data.CompleteMultipartUploadResult, {
1444+
var CompleteMultipartUploadResult = data.CompleteMultipartUploadResult || {};
1445+
var result = util.extend(CompleteMultipartUploadResult, {
14401446
Location: url,
14411447
statusCode: data.statusCode,
14421448
headers: data.headers,
@@ -1497,7 +1503,7 @@ function multipartList(params, callback) {
14971503
data.ListMultipartUploadsResult.Upload = Upload;
14981504
data.ListMultipartUploadsResult.CommonPrefixes = CommonPrefixes;
14991505
}
1500-
var result = util.clone(data.ListMultipartUploadsResult);
1506+
var result = util.clone(data.ListMultipartUploadsResult || {});
15011507
util.extend(result, {
15021508
statusCode: data.statusCode,
15031509
headers: data.headers,
@@ -1541,11 +1547,12 @@ function multipartListPart(params, callback) {
15411547
if (err) {
15421548
return callback(err);
15431549
}
1544-
var Part = data.ListPartsResult.Part || [];
1550+
var ListPartsResult = data.ListPartsResult || {};
1551+
var Part = ListPartsResult.Part || [];
15451552
Part = util.isArray(Part) ? Part : [Part];
15461553

1547-
data.ListPartsResult.Part = Part;
1548-
var result = util.clone(data.ListPartsResult);
1554+
ListPartsResult.Part = Part;
1555+
var result = util.clone(ListPartsResult);
15491556
util.extend(result, {
15501557
statusCode: data.statusCode,
15511558
headers: data.headers,

0 commit comments

Comments
 (0)