From 242072affee1f214e92a3d11f2850f400946082b Mon Sep 17 00:00:00 2001 From: Anis Elleuch Date: Mon, 29 Jan 2018 17:43:55 +0100 Subject: [PATCH] bucketExists: Return consistent NotFound error code bucketExists() currently returns NoSuchBucket or NotFound error code depending if region is specified in Minio Client initialization. This PR always specifies us-east-1 region in HEAD bucket call to avoid the internal code fetching for bucket location and returning NoSuchBucket error code. --- src/main/minio.js | 10 +++++++++- src/test/functional/functional-tests.js | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/minio.js b/src/main/minio.js index 16cdf25e6..d82df8bca 100644 --- a/src/main/minio.js +++ b/src/main/minio.js @@ -647,7 +647,15 @@ export class Client { throw new TypeError('callback should be of type "function"') } var method = 'HEAD' - this.makeRequest({method, bucketName}, '', 200, '', false, cb) + var pathStyle = true + this.makeRequest({method, bucketName, pathStyle}, '', 200, 'us-east-1', false, (e) => { + if (e && e.code == 'MovedPermanently') { + // MovePermanently status code implicitly says the bucket exists + // in a specific region, therefore we return a success here. + cb(null) + } + cb(e) + }) } // Remove a bucket. diff --git a/src/test/functional/functional-tests.js b/src/test/functional/functional-tests.js index 4d7381772..98240dc15 100644 --- a/src/test/functional/functional-tests.js +++ b/src/test/functional/functional-tests.js @@ -191,7 +191,7 @@ describe('functional tests', function() { step(`bucketExists(bucketName, cb)_bucketName:${bucketName}_`, done => client.bucketExists(bucketName, done)) step(`bucketExists(bucketName, cb)_bucketName:${bucketName}random_`, done => { client.bucketExists(bucketName + 'random', (e) => { - if (e.code === 'NoSuchBucket') return done() + if (e.code === 'NotFound') return done() done(new Error()) }) })