Skip to content

Commit

Permalink
bucketExists: Return consistent NotFound error code
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
vadmeste committed Jan 30, 2018
1 parent bb5c105 commit 242072a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/main/minio.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/test/functional/functional-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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())
})
})
Expand Down

0 comments on commit 242072a

Please sign in to comment.