Skip to content

Commit 156db07

Browse files
authored
Merge pull request #105 from livehigh/feat/env-warning
feat:新增sdk运行环境错误提示
2 parents 02f4ee2 + 6baa4ca commit 156db07

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

sdk/advance.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,7 +1041,7 @@ function sliceCopyFile(params, callback) {
10411041

10421042
FileSize = params.FileSize = data.headers['content-length'];
10431043
if (FileSize === undefined || !FileSize) {
1044-
callback(util.error(new Error('get Content-Length error, please add "Content-Length" to CORS ExposeHeader setting.')));
1044+
callback(util.error(new Error('get Content-Length error, please add "Content-Length" to CORS ExposeHeader setting.( 获取Content-Length失败,请在CORS ExposeHeader设置中添加Content-Length,请参考文档:https://cloud.tencent.com/document/product/436/13318 )')));
10451045
return;
10461046
}
10471047

@@ -1148,7 +1148,7 @@ function downloadFile(params, callback) {
11481148
// 获取文件大小
11491149
FileSize = params.FileSize = parseInt(data.headers['content-length']);
11501150
if (FileSize === undefined || !FileSize) {
1151-
callback(util.error(new Error('get Content-Length error, please add "Content-Length" to CORS ExposeHeader setting.')));
1151+
callback(util.error(new Error('get Content-Length error, please add "Content-Length" to CORS ExposeHeader setting.( 获取Content-Length失败,请在CORS ExposeHeader设置中添加Content-Length,请参考文档:https://cloud.tencent.com/document/product/436/13318 )')));
11521152
return;
11531153
}
11541154

sdk/cos.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ var COS = function (options) {
5959
if (this.options.AppId) {
6060
console.warn('warning: AppId has been deprecated, Please put it at the end of parameter Bucket(E.g: "test-1250000000").');
6161
}
62+
if (util.isWeb()) {
63+
console.warn('warning: cos-nodejs-sdk-v5 不支持浏览器使用,请改用 cos-js-sdk-v5,参考文档: https://cloud.tencent.com/document/product/436/11459');
64+
console.warn('warning: cos-nodejs-sdk-v5 does not support browsers. Please use cos-js-sdk-v5 instead, See: https://cloud.tencent.com/document/product/436/11459');
65+
}
6266
event.init(this);
6367
task.init(this);
6468
};

sdk/util.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,10 @@ var error = function (err, opt) {
625625
return err;
626626
}
627627

628+
var isWeb = function () {
629+
return typeof window === 'object';
630+
}
631+
628632
var util = {
629633
noop: noop,
630634
formatParams: formatParams,
@@ -657,6 +661,7 @@ var util = {
657661
getV4Auth: getV4Auth,
658662
isBrowser: false,
659663
obj2str: obj2str,
664+
isWeb: isWeb,
660665
};
661666

662667
module.exports = util;

0 commit comments

Comments
 (0)