Skip to content

Commit 02393e7

Browse files
committed
feat: add nextAppendPosition
1 parent 9da3001 commit 02393e7

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

lib/client.js

+4
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,10 @@ proto.requestError = async function requestError(result) {
341341
err.code = info.Code;
342342
err.requestId = info.RequestId;
343343
err.hostId = info.HostId;
344+
// https://help.aliyun.com/zh/oss/support/http-status-code-409#section-rmc-hvd-j38
345+
if (info.Code === 'PositionNotEqualToLength' && result.headers && result.headers['x-oss-next-append-position']) {
346+
err.nextAppendPosition = result.headers['x-oss-next-append-position'];
347+
}
344348
}
345349

346350
debug('generate error %j', err);

test/object.test.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -2075,13 +2075,13 @@ describe('test/object.test.js', () => {
20752075
it('should error when positio not match', async () => {
20762076
await store.append(name, Buffer.from('foo'));
20772077

2078-
try {
2079-
await store.append(name, Buffer.from('foo'));
2080-
throw new Error('should not run');
2081-
} catch (err) {
2082-
assert(err.message === 'Position is not equal to file length');
2083-
assert(err.name === 'PositionNotEqualToLengthError');
2084-
}
2078+
await assert.rejects(
2079+
store.append(name, Buffer.from('foo')),
2080+
err =>
2081+
err.message === 'Position is not equal to file length' &&
2082+
err.name === 'PositionNotEqualToLengthError' &&
2083+
err.nextAppendPosition === '3'
2084+
);
20852085
});
20862086

20872087
it('should use nextAppendPosition to append next', async () => {

0 commit comments

Comments
 (0)