I have came across this bug. When I am updating a user I get following error from the interface:
Cannot read property 'hasOwnProperty' of undefined
The weird thing is, the user updates even when this error message is displayed. Also, there is no error in developer console.
Here is the part of the code in my ODataProvider that should update the user.
case UPDATE:
url = `${apiUrl}/${resource}(${params.id})`;
options.method = 'PUT';
params.data = removeProperties(params.data, ['id', 'odata', 'odata.metadata']);
options.body = JSON.stringify(params.data);
break;
removeProperties constant:
const removeProperties = (data, props) => {
for (let prop of props) {
delete data[prop];
}
return data;
}
Any idea how to solve this?
Thank you in advance.
Related
Making a command to take a random photo of a waifu in this case, and posting it in the channel
Code here:
if (command === 'waifu') {
const waifu = new Discord.MessageEmbed()
got('https://waifu.pics/api/sfw/waifu').then(response => {
let content = JSON.parse(response.body);
let waifuUrl = content[0].data.children[0].data.url;
let waifuImage = content[0].data.children[0].data.url;
waifu.setImage(`${waifuImage}`)
waifu.setURL(`${waifuUrl}`)
waifu.setColor('#ffb9f4')
waifu.setFooter(`Requested by ${message.author.user}`)
waifu.setTimestamp()
waifu.setAuthor(`waifu.pics`, `https://waifu.pics/`)
message.channel.send(waifu)
});
};
The API should be correct. After a few small changes, I tried console logging the JSON and it did output the correct thing. But when running the code in discord, it outputted a TypeError: Cannot read property 'data' of undefined error. I cannot seem to figure out the problem
if (command === 'waifu') {
const waifu = new Discord.MessageEmbed()
get('https://waifu.pics/api/sfw/waifu').then(response => {
let content = response.body;
let waifuUrl = content.url;
let waifuImage = content.url;
waifu.setImage(`${waifuImage}`)
waifu.setURL(`${waifuUrl}`)
waifu.setColor('#ffb9f4')
waifu.setFooter(`Requested by ${message.author.username}`)
waifu.setTimestamp()
waifu.setAuthor(`waifu.pics`, `https://waifu.pics/`)
message.channel.send(waifu)
});
};
You thought a little bit complicated ^^ You had something with children and data, although the API just gives an URL. You don't even have to parse it. And you have used the function got(), which you have to replace with get().
I fixed your code just copy it from above.
when i kick a user with this command the audit logs show [object Onject] rather than the reason. if i were to replace all instances of kick in this command with ban it would work fine, but for some reason it's just kick where this issue occurs.
any ideas?
const caseInsensitive = message.content.toLowerCase();
const arguments = caseInsensitive.substring(prefix.length).split(` `);
const mention = message.mentions.users.first();
const member = message.guild.member(mention);
const reason = (!arguments[2]) ? `none` : `${arguments[2]}`
case `kick`:
if (!message.member.hasPermission(`KICK_MEMBERS`)) return;
if (!arguments[1]) return message.channel.send(`specify user`)
if (!mention) return message.channel.send(`couldn't find user`)
if (message.author === mention) return message.channel.send(`don't commit suicide`)
if (!member.kickable) return message.channel.send(`can't kick user`)
member.kick({ reason: `${reason}` }).then(
message.channel.send(`user has ben korked`))
break;
This is the problem.
You're passing an object into the member.kick() function.
According to the documentation, the parameters are supposed to be member.kick(reason), not member.kick({ reason }).
Hope this helps.
So, I'm attempting to pass a user's ip address in my app, as follows:
pages/Item.js
const Item = props => (
<div>
<SingleItem id={props.query.id} userIP={props.userIP} />
</div>
);
Item.getInitialProps = async ({ req }) => {
const userIP = req.headers['x-real-ip'] || req.connection.remoteAddress
return { userIP }
}
export default withAmp(Item, { hybrid: true });
but get the above mentioned error message (See attached image) when navigating to the page. But if I then do a hard reload of the page the ip details are correctly displayed to the page.
What am I overlooking here and is there a better way to achieve this, for example obtaining the ip address from headers in _document.js?
req will only be available when getInitialProps is called on the server. This is why it works when you do a refresh on the page.
When navigating to the page there is no server render so getInitialProps will be called on the client. Therefore, req will be undefined.
You can wrap the assignment in a condition to check if req is defined to prevent the error:
Item.getInitialProps = async ({ req }) => {
let userIP
if (req) {
userIP = req.headers['x-real-ip'] || req.connection.remoteAddress
}
return { userIP }
}
However, if you want to have userIP available on every page, regardless of whether it's server or client rendered, then you will need to find a way to store it on first load, whichever page that may be.
Perhaps you could store it using context.
There is am example of using context here:
https://github.com/zeit/next.js/tree/master/examples/with-context-api
I hope this helps.
I am facing the below issue where I am trying to save JSON data coming from my API into an array of my Model object. However, when I console.log the array it prints "undefined". I even tried to print a simple array and it still says "undefined". I am not sure if I am missing anything here. My code is given below. Can some one please help as I am new to Angular 2 and TypeScript.
results : Array<Recipes> = new Array(20);
sample = ['one','two','three'];
getResults(): Observable<Recipes[]>{
return this.http.get('<my API here which works perfectly.>')
.map(this.extractData)
.catch(this.handleErrorObservable);
}
private extractData(res: Response) {
let body = res.json();
console.log(this.sample); **---> This prints undefined in console**
console.log(body);
console.log(body.pagination.count);
let total_no_of_results = body.pagination.count;
let no_of_results;
for(no_of_results = 0; no_of_results < total_no_of_results; no_of_results++) {
//this.results[no_of_results] = new Recipes();
this.results[no_of_results] = body.data[no_of_results].embed_url; **---> This gives "Cannot set property '0' of undefined" error and program exits**
//this.results.push(image);
}
console.log(this.results);
return this.results;
}
private handleErrorObservable (error: Response | any) {
console.error(error.message || error);
return Observable.throw(error.message || error);
}
If you want to use this inside extractData you need
.map(this.extractData.bind(this))
or
.map((data) => this.extractData(data))
otherwise this won't point to the current class' instance.
I followed along Thinksters tutorial about firebase and angularjs
It worked great but I wanted to use the new functionality of $asArray() which required an update of angularfire (0.8).
Somehow this results in different TypeError (TypeError: undefined is not a function). For instanc on:
var query = $firebase(ref.startAt(authUser.uid).endAt(authUser.uid));
query.$on('loaded', function () { //ERROR LINE
setCurrentUser(query.$getIndex()[0]);
and
findByUsername: function (username) {
if (username) {
return users.$child(username); //ERROR LINE
}
}
I'm still able to sign in which means that i have connetction with Firebase. Does anybody have an idea of what went wrong or if I have to update anything more to get this working again?
EDIT:
my setCurrentUser-method:
function setCurrentUser (username) {
$rootScope.currentUser = User.findByUsername(username);
}
I've made an attempt to change my findByUsername-method:
findByUsername: function (username) {
if (username) {
return (users.$getRecord(username));
}
}
(relates to)
var ref = new Firebase(FIREBASE_URL + 'users');
var users = $firebase(ref).$asArray();
Still don't know a good way to search through my firebase-array correctly without .$child(username). Do I need a loop?