Skip to content

Commit

Permalink
修改容错
Browse files Browse the repository at this point in the history
  • Loading branch information
carsonxu committed Mar 15, 2018
1 parent 1bedb79 commit 2dac011
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 52 deletions.
57 changes: 32 additions & 25 deletions dist/cos-js-sdk-v5.js
Original file line number Diff line number Diff line change
Expand Up @@ -1679,15 +1679,16 @@ function getBucket(params, callback) {
if (err) {
return callback(err);
}
var contents = data.ListBucketResult.Contents || [];
var CommonPrefixes = data.ListBucketResult.CommonPrefixes || [];
var ListBucketResult = data.ListBucketResult || {};
var Contents = ListBucketResult.Contents || [];
var CommonPrefixes = ListBucketResult.CommonPrefixes || [];

contents = util.isArray(contents) ? contents : [contents];
Contents = util.isArray(Contents) ? Contents : [Contents];
CommonPrefixes = util.isArray(CommonPrefixes) ? CommonPrefixes : [CommonPrefixes];

var result = util.clone(data.ListBucketResult);
var result = util.clone(ListBucketResult);
util.extend(result, {
Contents: contents,
Contents: Contents,
CommonPrefixes: CommonPrefixes,
statusCode: data.statusCode,
headers: data.headers
Expand Down Expand Up @@ -1747,10 +1748,11 @@ function getBucketAcl(params, callback) {
if (err) {
return callback(err);
}
var Owner = data.AccessControlPolicy.Owner || {};
var Grant = data.AccessControlPolicy.AccessControlList.Grant || [];
var AccessControlPolicy = data.AccessControlPolicy || {};
var Owner = AccessControlPolicy.Owner || {};
var Grant = AccessControlPolicy.AccessControlList.Grant || [];
Grant = util.isArray(Grant) ? Grant : [Grant];
var result = decodeAcl(data.AccessControlPolicy);
var result = decodeAcl(AccessControlPolicy);
if (data.headers && data.headers['x-cos-acl']) {
result.ACL = data.headers['x-cos-acl'];
}
Expand Down Expand Up @@ -2423,12 +2425,13 @@ function listObjectVersions(params, callback) {
if (err) {
return callback(err);
}
var DeleteMarkers = data.ListVersionsResult.DeleteMarker || [];
var ListVersionsResult = data.ListVersionsResult || {};
var DeleteMarkers = ListVersionsResult.DeleteMarker || [];
DeleteMarkers = util.isArray(DeleteMarkers) ? DeleteMarkers : [DeleteMarkers];
var Versions = data.ListVersionsResult.Version || [];
var Versions = ListVersionsResult.Version || [];
Versions = util.isArray(Versions) ? Versions : [Versions];

var result = util.clone(data.ListVersionsResult);
var result = util.clone(ListVersionsResult);
delete result.DeleteMarker;
delete result.Version;
util.extend(result, {
Expand Down Expand Up @@ -2655,10 +2658,11 @@ function getObjectAcl(params, callback) {
if (err) {
return callback(err);
}
var Owner = data.AccessControlPolicy.Owner || {};
var Grant = data.AccessControlPolicy.AccessControlList.Grant || [];
var AccessControlPolicy = data.AccessControlPolicy || {};
var Owner = AccessControlPolicy.Owner || {};
var Grant = AccessControlPolicy.AccessControlList && AccessControlPolicy.AccessControlList.Grant || [];
Grant = util.isArray(Grant) ? Grant : [Grant];
var result = decodeAcl(data.AccessControlPolicy);
var result = decodeAcl(AccessControlPolicy);
if (data.headers && data.headers['x-cos-acl']) {
result.ACL = data.headers['x-cos-acl'];
}
Expand Down Expand Up @@ -2743,7 +2747,7 @@ function optionsObject(params, callback) {
headers: headers
}, function (err, data) {
if (err) {
if (err.statusCode && err.statusCode == 403) {
if (err.statusCode && err.statusCode === 403) {
return callback(null, {
OptionsForbidden: true,
statusCode: err.statusCode
Expand Down Expand Up @@ -2804,7 +2808,7 @@ function putObjectCopy(params, callback) {
if (err) {
return callback(err);
}
var result = util.clone(data.CopyObjectResult);
var result = util.clone(data.CopyObjectResult || {});
util.extend(result, {
statusCode: data.statusCode,
headers: data.headers
Expand All @@ -2827,7 +2831,7 @@ function uploadPartCopy(params, callback) {
if (err) {
return callback(err);
}
var result = util.clone(data.CopyObjectResult);
var result = util.clone(data.CopyObjectResult || {});
util.extend(result, {
statusCode: data.statusCode,
headers: data.headers
Expand Down Expand Up @@ -2857,13 +2861,14 @@ function deleteMultipleObject(params, callback) {
if (err) {
return callback(err);
}
var Deleted = data.DeleteResult.Deleted || [];
var Errors = data.DeleteResult.Error || [];
var DeleteResult = data.DeleteResult || {};
var Deleted = DeleteResult.Deleted || [];
var Errors = DeleteResult.Error || [];

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

var result = util.clone(data.DeleteResult);
var result = util.clone(DeleteResult);
util.extend(result, {
Error: Errors,
Deleted: Deleted,
Expand Down Expand Up @@ -3050,7 +3055,8 @@ function multipartComplete(params, callback) {
object: params.Key,
isLocation: true
});
var result = util.extend(data.CompleteMultipartUploadResult, {
var CompleteMultipartUploadResult = data.CompleteMultipartUploadResult || {};
var result = util.extend(CompleteMultipartUploadResult, {
Location: url,
statusCode: data.statusCode,
headers: data.headers
Expand Down Expand Up @@ -3111,7 +3117,7 @@ function multipartList(params, callback) {
data.ListMultipartUploadsResult.Upload = Upload;
data.ListMultipartUploadsResult.CommonPrefixes = CommonPrefixes;
}
var result = util.clone(data.ListMultipartUploadsResult);
var result = util.clone(data.ListMultipartUploadsResult || {});
util.extend(result, {
statusCode: data.statusCode,
headers: data.headers
Expand Down Expand Up @@ -3154,11 +3160,12 @@ function multipartListPart(params, callback) {
if (err) {
return callback(err);
}
var Part = data.ListPartsResult.Part || [];
var ListPartsResult = data.ListPartsResult || {};
var Part = ListPartsResult.Part || [];
Part = util.isArray(Part) ? Part : [Part];

data.ListPartsResult.Part = Part;
var result = util.clone(data.ListPartsResult);
ListPartsResult.Part = Part;
var result = util.clone(ListPartsResult);
util.extend(result, {
statusCode: data.statusCode,
headers: data.headers
Expand Down
2 changes: 1 addition & 1 deletion dist/cos-js-sdk-v5.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cos-js-sdk-v5",
"version": "0.3.10",
"version": "0.3.11",
"description": "cos js sdk v5",
"main": "index.js",
"scripts": {
Expand Down
57 changes: 32 additions & 25 deletions src/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,16 @@ function getBucket(params, callback) {
if (err) {
return callback(err);
}
var contents = data.ListBucketResult.Contents || [];
var CommonPrefixes = data.ListBucketResult.CommonPrefixes || [];
var ListBucketResult = data.ListBucketResult || {};
var Contents = ListBucketResult.Contents || [];
var CommonPrefixes = ListBucketResult.CommonPrefixes || [];

contents = util.isArray(contents) ? contents : [contents];
Contents = util.isArray(Contents) ? Contents : [Contents];
CommonPrefixes = util.isArray(CommonPrefixes) ? CommonPrefixes : [CommonPrefixes];

var result = util.clone(data.ListBucketResult);
var result = util.clone(ListBucketResult);
util.extend(result, {
Contents: contents,
Contents: Contents,
CommonPrefixes: CommonPrefixes,
statusCode: data.statusCode,
headers: data.headers,
Expand Down Expand Up @@ -128,10 +129,11 @@ function getBucketAcl(params, callback) {
if (err) {
return callback(err);
}
var Owner = data.AccessControlPolicy.Owner || {};
var Grant = data.AccessControlPolicy.AccessControlList.Grant || [];
var AccessControlPolicy = data.AccessControlPolicy || {};
var Owner = AccessControlPolicy.Owner || {};
var Grant = AccessControlPolicy.AccessControlList.Grant || [];
Grant = util.isArray(Grant) ? Grant : [Grant];
var result = decodeAcl(data.AccessControlPolicy);
var result = decodeAcl(AccessControlPolicy);
if (data.headers && data.headers['x-cos-acl']) {
result.ACL = data.headers['x-cos-acl'];
}
Expand Down Expand Up @@ -809,12 +811,13 @@ function listObjectVersions(params, callback) {
if (err) {
return callback(err);
}
var DeleteMarkers = data.ListVersionsResult.DeleteMarker || [];
var ListVersionsResult = data.ListVersionsResult || {};
var DeleteMarkers = ListVersionsResult.DeleteMarker || [];
DeleteMarkers = util.isArray(DeleteMarkers) ? DeleteMarkers : [DeleteMarkers];
var Versions = data.ListVersionsResult.Version || [];
var Versions = ListVersionsResult.Version || [];
Versions = util.isArray(Versions) ? Versions : [Versions];

var result = util.clone(data.ListVersionsResult);
var result = util.clone(ListVersionsResult);
delete result.DeleteMarker;
delete result.Version;
util.extend(result, {
Expand Down Expand Up @@ -1039,10 +1042,11 @@ function getObjectAcl(params, callback) {
if (err) {
return callback(err);
}
var Owner = data.AccessControlPolicy.Owner || {};
var Grant = data.AccessControlPolicy.AccessControlList.Grant || [];
var AccessControlPolicy = data.AccessControlPolicy || {};
var Owner = AccessControlPolicy.Owner || {};
var Grant = AccessControlPolicy.AccessControlList && AccessControlPolicy.AccessControlList.Grant || [];
Grant = util.isArray(Grant) ? Grant : [Grant];
var result = decodeAcl(data.AccessControlPolicy);
var result = decodeAcl(AccessControlPolicy);
if (data.headers && data.headers['x-cos-acl']) {
result.ACL = data.headers['x-cos-acl'];
}
Expand Down Expand Up @@ -1127,7 +1131,7 @@ function optionsObject(params, callback) {
headers: headers,
}, function (err, data) {
if (err) {
if (err.statusCode && err.statusCode == 403) {
if (err.statusCode && err.statusCode === 403) {
return callback(null, {
OptionsForbidden: true,
statusCode: err.statusCode
Expand Down Expand Up @@ -1188,7 +1192,7 @@ function putObjectCopy(params, callback) {
if (err) {
return callback(err);
}
var result = util.clone(data.CopyObjectResult);
var result = util.clone(data.CopyObjectResult || {});
util.extend(result, {
statusCode: data.statusCode,
headers: data.headers,
Expand All @@ -1211,7 +1215,7 @@ function uploadPartCopy(params, callback) {
if (err) {
return callback(err);
}
var result = util.clone(data.CopyObjectResult);
var result = util.clone(data.CopyObjectResult || {});
util.extend(result, {
statusCode: data.statusCode,
headers: data.headers,
Expand Down Expand Up @@ -1241,13 +1245,14 @@ function deleteMultipleObject(params, callback) {
if (err) {
return callback(err);
}
var Deleted = data.DeleteResult.Deleted || [];
var Errors = data.DeleteResult.Error || [];
var DeleteResult = data.DeleteResult || {};
var Deleted = DeleteResult.Deleted || [];
var Errors = DeleteResult.Error || [];

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

var result = util.clone(data.DeleteResult);
var result = util.clone(DeleteResult);
util.extend(result, {
Error: Errors,
Deleted: Deleted,
Expand Down Expand Up @@ -1436,7 +1441,8 @@ function multipartComplete(params, callback) {
object: params.Key,
isLocation: true,
});
var result = util.extend(data.CompleteMultipartUploadResult, {
var CompleteMultipartUploadResult = data.CompleteMultipartUploadResult || {};
var result = util.extend(CompleteMultipartUploadResult, {
Location: url,
statusCode: data.statusCode,
headers: data.headers,
Expand Down Expand Up @@ -1497,7 +1503,7 @@ function multipartList(params, callback) {
data.ListMultipartUploadsResult.Upload = Upload;
data.ListMultipartUploadsResult.CommonPrefixes = CommonPrefixes;
}
var result = util.clone(data.ListMultipartUploadsResult);
var result = util.clone(data.ListMultipartUploadsResult || {});
util.extend(result, {
statusCode: data.statusCode,
headers: data.headers,
Expand Down Expand Up @@ -1541,11 +1547,12 @@ function multipartListPart(params, callback) {
if (err) {
return callback(err);
}
var Part = data.ListPartsResult.Part || [];
var ListPartsResult = data.ListPartsResult || {};
var Part = ListPartsResult.Part || [];
Part = util.isArray(Part) ? Part : [Part];

data.ListPartsResult.Part = Part;
var result = util.clone(data.ListPartsResult);
ListPartsResult.Part = Part;
var result = util.clone(ListPartsResult);
util.extend(result, {
statusCode: data.statusCode,
headers: data.headers,
Expand Down

0 comments on commit 2dac011

Please sign in to comment.