Skip to content

Commit

Permalink
fix: merge conflict #726 (#892)
Browse files Browse the repository at this point in the history
* fix: merge conflict

* test: ResponseTimeoutError
  • Loading branch information
beajer authored Nov 23, 2020
1 parent 31fbd2c commit 6c77ecc
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 5 deletions.
8 changes: 7 additions & 1 deletion lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@ proto.request = async function request(params) {
return this.request(params);
}
}
if (err.name === 'ResponseTimeoutError') {
err.message = `${err.message.split(',')[0]}, please increase the timeout or use multipartDownload.`;
}
throw err;
}

Expand Down Expand Up @@ -290,7 +293,10 @@ proto.parseXML = function parseXMLThunk(str) {

proto.requestError = async function requestError(result) {
let err = null;
if (!result.data || !result.data.length) {
if (result.name === 'ResponseTimeoutError') {
err = new Error(result.message);
err.name = result.name;
} else if (!result.data || !result.data.length) {
if (result.status === -1 || result.status === -2) { // -1 is net error , -2 is timeout
err = new Error(result.message);
err.name = result.name;
Expand Down
21 changes: 21 additions & 0 deletions test/browser/browser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1661,6 +1661,27 @@ describe('browser', () => {

store.urllib.request.restore();
});

it('should request throw ResponseTimeoutError', async () => {
const fileName = await utils.createTempFile('multipart-upload-file', 1024 * 1024);// 1m
const name = `${prefix}multipart/upload-file`;

const stubNetError = sinon.stub(store.urllib, 'request');
const netErr = new Error('ResponseTimeoutError');
netErr.status = -1;
netErr.code = 'ResponseTimeoutError';
netErr.name = 'ResponseTimeoutError';
stubNetError.throws(netErr);

let netErrs;
try {
await store.multipartUpload(name, fileName);
} catch (err) {
netErrs = err;
}
assert.strictEqual(netErrs.name, 'ResponseTimeoutError');
store.urllib.request.restore();
});
});

describe('options.headerEncoding', () => {
Expand Down
4 changes: 2 additions & 2 deletions test/node/bukcet_worm.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const utils = require('./utils');
const oss = require('../..');
const config = require('../config').oss;

describe('test/bucket.test.js', () => {
describe('test/bucket_worm.test.js', () => {
const { prefix } = utils;
let store;
let bucket;
Expand All @@ -26,7 +26,7 @@ describe('test/bucket.test.js', () => {

config.region = defaultRegion;
store = oss(config);
bucket = `ali-oss-test-bucket-${prefix.replace(/[/.]/g, '-')}`;
bucket = `ali-oss-test-bucket-worm-${prefix.replace(/[/.]/g, '-')}`;
bucket = bucket.substring(0, bucket.length - 1);

const result = await store.putBucket(bucket);
Expand Down
20 changes: 20 additions & 0 deletions test/node/multipart.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,27 @@ describe('test/multipart.test.js', () => {

assert.equal(true, netErr && Object.keys(netErrs).length !== 0);
assert.equal(netErrs.status, -1);
store.urllib.request.restore();
});

it('should request throw ResponseTimeoutError', async () => {
const fileName = await utils.createTempFile('multipart-upload-file', 1024 * 1024);// 1m
const name = `${prefix}multipart/upload-file`;

const stubNetError = sinon.stub(store.urllib, 'request');
const netErr = new Error('ResponseTimeoutError');
netErr.status = -1;
netErr.code = 'ResponseTimeoutError';
netErr.name = 'ResponseTimeoutError';
stubNetError.throws(netErr);

let netErrs;
try {
await store.multipartUpload(name, fileName);
} catch (err) {
netErrs = err;
}
assert.strictEqual(netErrs.name, 'ResponseTimeoutError');
store.urllib.request.restore();
});
});
Expand Down
4 changes: 2 additions & 2 deletions test/node/multiversion.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ describe('test/multiversion.test.js', () => {
noncurrentDays: 1
}
}]);
assert.equal(putresult1.res.status, 200);
assert.strictEqual(putresult1.res.status, 200);
const { rules } = await store.getBucketLifecycle(bucket);
assert.strictEqual(rules[0].noncurrentVersionExpiration.noncurrentDays, '1');
});
Expand Down Expand Up @@ -199,7 +199,7 @@ describe('test/multiversion.test.js', () => {
});

// 暂停多版本, 进行copy, copy后object的versionId为null
it('should copy latest object when no versionId', async () => {
it('should copy latest object when bucket is suspended', async () => {
const target = `${name.replace('file.js', 'file-target-suspended.js')}`;
const suspendedRes = await store.putBucketVersioning(bucket, suspended);
assert.strictEqual(suspendedRes.res.status, 200);
Expand Down

0 comments on commit 6c77ecc

Please sign in to comment.