I'm trying to send a bug report via API, and have an authentication token in my apps metadata settings, which works usually. I refactored that logic out of my main.js and into it's own class, but now I'm receiving 403 errors, which I can only imagine is due to how I'm referencing the token.
class Logger {
constructor(settings) {
// getting the settings here and assigning it to the constructor variable
this.settings = settings;
}
static async logInfo(data = {}) {
console.log('Hello!')
const url = 'https://sampleUrl'
const response = await fetch(url, {
method: 'POST',
headers: {
"X-TrackerToken": `${metadata.settings.pivotal_token}`,
"Content-Type": "application/json"
},
body: JSON.stringify(data)
});
return response.json();
}
}
const metadata = {
settings: ''
}
const logger = new Logger(metadata.settings);
How I call the Logger class in Main.js
Logger.logInfo(metadata.settings, bugInfo).then(console.log('print'))
})
On mouse hover the tooltip returns the message 'Property does not exist on type String error.', before the move into it's own class I referenced it with the same syntax, so not sure how to proceed here.
You are passing the settings with the constructor, so you need to use this setting in the Logger class, but you are using another variable for X-TrackerToken that is not defined.
const metaData = {
settings: ""
}
metadata.settings.pivotal_token // ---> undefined
You are trying to get pivotal_token from the settings which is a string and obviously, there is no pivotal_token method existing for your settings strings.
You are doing metadta.settings.pivotal_token but metadta.settings is a string. It's not having any pivotal_token property.