Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: develop to master by xutao #1244

Merged
merged 13 commits into from
Sep 4, 2023
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4551,13 +4551,33 @@ Will put to all clients.

Each error return by OSS server will contains these properties:


- name {String} error name
- message {String} error message
- requestId {String} uuid for this request, if you meet some unhandled problem,
you can send this request id to OSS engineer to find out what's happend.
- hostId {String} OSS cluster name for this request

The following table lists the OSS error codes:
### ResponseTimeoutError
The request to get the object file cannot be returned within the default time, please set a longer timeout. Or change to use multipart to download

```javascript
client.get('example.txt', { timeout:60000 * 2})

client.get('example.txt', { headers:{ Range:`bytes=0-${ 1024 * 1024 * 100 }` } }) // Download the first 100MB
```

### ConnectionTimeoutError
The request link has timed out. Please check the network link status. If there is no problem with the network, please reduce the partSize or increase the timeout to retry.
```javascript
const client = new OSS({ ak, sk, retryMax:10 })

client.multipartUpload('example.txt', { timeout:60000 * 2 })

client.multipartUpload('example.txt', { partSize: 1024 * 512 }) // partSize 512KB
```

### The following table lists the OSS error codes:

[More code info](https://help.aliyun.com/knowledge_detail/32005.html)

Expand Down
5 changes: 4 additions & 1 deletion lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,10 @@ async function request(params) {
}

if (err.name === 'ResponseTimeoutError') {
err.message = `${err.message.split(',')[0]}, please increase the timeout or use multipartDownload.`;
err.message = `${err.message.split(',')[0]}, please increase the timeout ,see more details at https://github.com/ali-sdk/ali-oss#responsetimeouterror`;
}
if (err.name === 'ConnectionTimeoutError') {
err.message = `${err.message.split(',')[0]}, please increase the timeout or reduce the partSize ,see more details at https://github.com/ali-sdk/ali-oss#connectiontimeouterror`;
}
throw err;
}
Expand Down
4 changes: 4 additions & 0 deletions lib/common/object/head.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const { checkEnv } = require('../utils/checkEnv');
const proto = exports;
/**
* head
Expand All @@ -7,6 +8,9 @@ const proto = exports;
*/

proto.head = async function head(name, options = {}) {
checkEnv(
'Because HeadObject has gzip enabled, head cannot get the file size correctly. If you need to get the file size, please use getObjectMeta'
shungang marked this conversation as resolved.
Show resolved Hide resolved
);
options.subres = Object.assign({}, options.subres);
if (options.versionId) {
options.subres.versionId = options.versionId;
Expand Down
1 change: 1 addition & 0 deletions lib/common/utils/checkEnv.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export declare function checkEnv(msg: string): void;
9 changes: 9 additions & 0 deletions lib/common/utils/checkEnv.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.checkEnv = void 0;
function checkEnv(msg) {
if (process.browser) {
console.warn(msg);
}
}
exports.checkEnv = checkEnv;
5 changes: 5 additions & 0 deletions lib/common/utils/checkEnv.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export function checkEnv(msg: string) {
if (process.browser) {
console.warn(msg);
}
}
4 changes: 4 additions & 0 deletions lib/common/utils/createRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const { encoder } = require('./encoder');
const { isIP } = require('./isIP');
const { setRegion } = require('./setRegion');
const { getReqUrl } = require('../client/getReqUrl');
const { isDingTalk } = require('./isDingTalk');
function getHeader(headers, name) {
return headers[name] || headers[name.toLowerCase()];
}
Expand Down Expand Up @@ -43,6 +44,9 @@ function createRequest(params) {
if (params.mime && params.mime.indexOf('/') > 0) {
headers['Content-Type'] = params.mime;
}
else if (isDingTalk()) {
headers['Content-Type'] = 'application/octet-stream';
}
else {
headers['Content-Type'] = mime.getType(params.mime || path.extname(params.object || ''));
}
Expand Down
3 changes: 3 additions & 0 deletions lib/common/utils/createRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const { encoder } = require('./encoder');
const { isIP } = require('./isIP');
const { setRegion } = require('./setRegion');
const { getReqUrl } = require('../client/getReqUrl');
const { isDingTalk } = require('./isDingTalk');

interface Headers {
[propName: string]: any;
Expand Down Expand Up @@ -58,6 +59,8 @@ export function createRequest(this: any, params) {
if (!getHeader(headers, 'Content-Type')) {
if (params.mime && params.mime.indexOf('/') > 0) {
headers['Content-Type'] = params.mime;
} else if (isDingTalk()) {
headers['Content-Type'] = 'application/octet-stream';
} else {
headers['Content-Type'] = mime.getType(params.mime || path.extname(params.object || ''));
}
Expand Down
1 change: 1 addition & 0 deletions lib/common/utils/isDingTalk.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export declare function isDingTalk(): boolean;
10 changes: 10 additions & 0 deletions lib/common/utils/isDingTalk.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isDingTalk = void 0;
function isDingTalk() {
if (process.browser && window.navigator.userAgent.toLowerCase().includes('aliapp(dingtalk')) {
return true;
}
return false;
}
exports.isDingTalk = isDingTalk;
6 changes: 6 additions & 0 deletions lib/common/utils/isDingTalk.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export function isDingTalk() {
if (process.browser && window.navigator.userAgent.toLowerCase().includes('aliapp(dingtalk')) {
return true;
}
return false;
}
Loading