Skip to content

Commit 3c00955

Browse files
authored
Merge pull request #305 from bcgov/bug/bucket-creds-conflict-error-responses
Create/update bucket endpoints: swap HTTP 403/409 response codes when encountering errors with S3 credentials, reword "bucket credentials mismatch" error message
2 parents 4af16cf + 07cb682 commit 3c00955

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

app/src/controllers/bucket.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ const controller = {
9090
log.warn(`Failure to validate bucket credentials: ${e.message}`, {
9191
function: '_validateCredentials',
9292
});
93-
throw new Problem(409, {
93+
throw new Problem(403, {
9494
detail: 'Unable to validate supplied credentials for the bucket',
9595
});
9696
}
@@ -128,7 +128,7 @@ const controller = {
128128
if (e instanceof UniqueViolationError) {
129129
// Grant permissions if credentials precisely match
130130
response = await bucketService.checkGrantPermissions(data).catch(permErr => {
131-
next(new Problem(403, { detail: permErr.message, instance: req.originalUrl }));
131+
next(new Problem(409, { detail: permErr.message, instance: req.originalUrl }));
132132
});
133133
} else {
134134
next(errorToProblem(SERVICE, e));

app/src/services/bucket.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ const service = {
7878
await bucketPermissionService.addPermissions(bucket.bucketId, perms, data.userId, trx);
7979
}
8080
} else {
81-
throw new Error('Bucket credential mismatch');
81+
throw new Error('The bucket already exists in COMS, but with different credentials. ' +
82+
'Please contact your object storage server admin, or whoever added the bucket first.');
8283
}
8384

8485
if (!etrx) await trx.commit();

app/tests/unit/controllers/bucket.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ describe('createBucketChild', () => {
357357
}));
358358
});
359359

360-
it('should return a 409 when bucket can not be validated', async () => {
360+
it('should return a 403 when bucket can not be validated', async () => {
361361
const req = {
362362
body: { bucketName: 'bucketName', subKey: 'subKey' },
363363
currentUser: CURRENT_USER,
@@ -404,7 +404,7 @@ describe('createBucketChild', () => {
404404
}));
405405

406406
expect(next).toHaveBeenCalledTimes(1);
407-
expect(next).toHaveBeenCalledWith(new Problem(409, {
407+
expect(next).toHaveBeenCalledWith(new Problem(403, {
408408
detail: 'Unable to validate supplied credentials for the bucket'
409409
}));
410410
});

0 commit comments

Comments
 (0)