Skip to content

Commit

Permalink
Merge pull request #143 from jrjohnson/v3-handle-404
Browse files Browse the repository at this point in the history
Handle NotFound S3 Response
  • Loading branch information
lukemelia authored Apr 30, 2024
2 parents 07023b0 + 131e1db commit 50de18b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 20 deletions.
31 changes: 13 additions & 18 deletions lib/s3.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,15 @@ var readFile = RSVP.denodeify(fs.readFile);
var mime = require('mime-types');
var joinUriSegments = require('./util/join-uri-segments');

function headObject(client, params) {
return new RSVP.Promise(function(resolve, reject) {
client.headObject(params, function(err, data) {
if (err && err.code === 'NotFound') {
return resolve();
}
else if (err) {
return reject(err);
}
else {
return resolve(data);
}
});
});
async function headObject(client, params) {
try {
return await client.headObject(params);
} catch (err) {
if (err.name === 'NotFound') {
return;
}
throw err;
}
}

module.exports = CoreObject.extend({
Expand All @@ -37,26 +32,26 @@ module.exports = CoreObject.extend({
this._plugin = plugin;

var providedS3Client = plugin.readConfig("s3Client");


if (profile && !providedS3Client) {
this._plugin.log("Using AWS profile from config", { verbose: true });
credentials = fromIni({ profile: profile });
}

if (endpoint) {
this._plugin.log('Using endpoint from config', { verbose: true });
this._plugin.log('Using endpoint from config', { verbose: true });
}

this._client = providedS3Client || new S3(config);

if (endpoint) {
this._client.config.endpoint = endpoint;
}
if (credentials) {
this._client.config.credentials = credentials;
}

},

upload: function(options) {
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/lib/s3-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ describe('s3', function() {
cb(undefined, revisionsData);
},

headObject: function(params, cb) {
headObject: async function(params, cb) {
headParams = params;
cb(undefined, currentData);
return currentData;
},

copyObject: function(params, cb) {
Expand Down

0 comments on commit 50de18b

Please sign in to comment.