Skip to content

Commit b5706f0

Browse files
authored
fix: respond with 2xx codes for webhooks (#20)
1 parent 3a9ba4f commit b5706f0

2 files changed

Lines changed: 12 additions & 5 deletions

File tree

src/actions/finish.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ const fields = [
2525
FILES_UNLISTED_FIELD,
2626
];
2727

28+
const MissingError = new HttpStatusError(200, '404: could not find upload');
29+
2830
/**
2931
* Finish upload
3032
* @param {Object} opts
@@ -41,9 +43,11 @@ module.exports = function completeFileUpload(opts) {
4143
return Promise
4244
.bind(this, key)
4345
.then(fetchData)
46+
.catchThrow({ statusCode: 404 }, MissingError)
4447
.then(data => {
4548
if (data[FILES_STATUS_FIELD] !== STATUS_PENDING) {
46-
throw new HttpStatusError(412, 'upload has already been marked as finished');
49+
// we do not send 412, because google might decide to delay notifications
50+
throw new HttpStatusError(200, '412: upload has already been marked as finished');
4751
}
4852

4953
const { uploadId } = data;
@@ -81,7 +85,8 @@ module.exports = function completeFileUpload(opts) {
8185
}
8286

8387
if (currentStatus !== STATUS_PENDING) {
84-
throw new HttpStatusError(412, 'upload was already processed');
88+
// we do not send 412, because google might decide to delay notifications
89+
throw new HttpStatusError(200, '412: upload was already processed');
8590
}
8691

8792
const uploadKey = `${FILES_DATA}:${uploadId}`;

test/suites/finish.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,14 @@ describe('finish upload suite', function suite() {
3737
});
3838
});
3939

40-
it('returns 404 on missing filename', function test() {
40+
it('returns 200: 404 on missing filename', function test() {
4141
return this
4242
.send({ filename: [md5(owner), uuid.v4(), uuid.v4()].join('/') })
4343
.reflect()
4444
.then(inspectPromise(false))
4545
.then(err => {
46-
assert.equal(err.statusCode, 404);
46+
assert.equal(err.statusCode, 200);
47+
assert.ok(/^404: /.test(err.message));
4748
});
4849
});
4950

@@ -73,7 +74,8 @@ describe('finish upload suite', function suite() {
7374
.reflect()
7475
.then(inspectPromise(false))
7576
.then(err => {
76-
assert.equal(err.statusCode, 412);
77+
assert.equal(err.statusCode, 200);
78+
assert.ok(/^412: /.test(err.message));
7779
});
7880
});
7981
});

0 commit comments

Comments
 (0)