I'm working on an Angular component. In a method in the typescript file I'm accessing an AWS S3 object with the headObject() method. In that method's callback function I'd like to be able to call the outer method again if the headObject() method fails. It seems like I should be structuring the methods using "fat arrow" operator to reference the outer method's this
variable, but I can't figure out the correct way to do it. If there's a better way please point me in that direction.
getNewPass = (parameter) => {
const bucket = new S3({
accessKeyId: '/*************/',
secretAccessKey: '/*************/',
region: '/*************/'
});
const params = {
Bucket: '/*************/',
Key: /*************/
}
bucket.headObject(params, function (err, data) {
if (err && err.code === 'NotFound') {
// HERE is where the issue is
this.getNewPass(parameter);
} else {
bucket.getSignedUrl('getObject', params, function(err, data) {
if (err) {
console.log('Error retrieving file: ', err);
return false;
} else {
console.log('Successfully retrieved file.', data);
window.location.href = data;
return true;
}
});
}
});
}
I've blocked out some sensitive information and changed a variable name but otherwise that's what I'm working on. Thanks for the help.