phonegap/web database errorcodes Explanation? - javascript

I want to show correct errors to the user if a transaction with a web database (Iยดm using Phonegap) fails. In the Error-Callback I ask for the error.code value to determine what went wrong.
The Documentations says this about it. However, I have a case where the transaction fails because a unique constraint is violated by inserting a value that already exists.
function saveErrorCB(err){
console.log(err.code + " " + err.message + " ");
}
err.code shows:
1
err.message shows here:
could not execute statement (19 constraint failed)
My point is, I want to know about other codes like "1". The Phonegap documentation doesnt mention it.

I think the Phonegap documentation does (eventually) link to a W3C page which then says...
UNKNOWN_ERR = 0
DATABASE_ERR = 1
VERSION_ERR = 2
TOO_LARGE_ERR = 3
QUOTA_ERR = 4
SYNTAX_ERR = 5
CONSTRAINT_ERR = 6
TIMEOUT_ERR = 7
It seems err.message is more useful - thanks for telling me about it!

Related

How to count amount of reactions in Discord.js v13?

I have tried so many things out, here's my current code
var green = toString(msg.reactions.cache.get('๐ŸŸฉ').count);
var red = toString(msg.reactions.cache.get('๐ŸŸฅ').count);
msg.reply("Poll has ended which was created by " + msg.author.username)
msg.reply(green + " " + red)
It gives this error
var green = toString(msg.reactions.cache.get('๐ŸŸฉ').count);
^
TypeError: Cannot read properties of undefined (reading 'count')
Please help!
I want it to display how many people reacted on ๐ŸŸฉ and ๐ŸŸฅ.
I'm not able to do that even after asking Discord.js experts, I can't understand how to get them.
I also want them to be a string, that's why I used The toString() function.
This is for a poll/vote bot I am making.
I react to the messages and still it shows this error.
This is Discord.js v13.
Thanks!
TheThiefingKing
let msg = await message.channel.messages.fetch("974311411314475059")
let reactsSize = msg.reactions.cache.get("โœ…").count
message.channel.send("โœ… Reacts on that message is: " + (+reactsSize))
You need to await message first after that you can fetch reactions.

Is there a better way of sending messages to specific channels in specific servers?

I'm trying to make a logs script, however, I can not get it to work. Is there a better way?
I've tried switching around the properties, but it doesn't seem to work.
client.on('message', message => {
var sender = message.member.user.tag
var channel = message.channel.name
var message = message.content
var server = message.guild
let embed = new Discord.RichEmbed()
.addField('**' + sender + '** said ' + message + ' in ' + channel + ', ' + server)
.setColor('#4286f4')
// This is the line I'm having problems with:
client.guilds.get('575957043211403265').channels.get('575957043211403267').sendEmbed(embed);
});
If the IDs you're using are correct, then your code should be valid, as long as you're using the library from the stable branch.
You're using the TextChannel.sendEmbed() method, which is deprecated: that means that it'll be removed in the future versions. If you installed the master branch that method won't be available (check the docs here).
There is another way of sending embeds:
TextChannel.send({ embed: yourEmbed });
In your case, it would be:
client.guilds.get('575957043211403265').channels.get('575957043211403267').send({ embed });
If that doesn't work, please include the error in your reply, you might have missed something in the question :)

Why is some of my code running before other ones?

So i was running my script and i was wondering why some of my code was running before eachother.
For example, i had a function, and i called it last, AFTER a message was supposed to be displayed. But instead it ran the function first THEN displayed the message.
Also, i was noticing with displaying messages, it would display in a random order each time. (Wierd Huh.)
I managed to fix some of this by creating a bunch of .this's, but i don't want to do that so much in the future as it makes code very confusing.
Here is a snippet of some of my code that this is happening to:
else if (input.startsWith('CALL')) {
//First
bot.sendMessage(message, ':arrow_right: Private Messaging You To Decrease Spam :arrow_left:');
//Second
bot.sendMessage(user.id, ':rotating_light: This feature is experimental. You may experience bugs/glitches when using it. :rotating_light: \n').then(() => getUser()); // << Third
var senderId = message.sender.id; // << Fourth
function getUser() {
try {
var userList = []
for (var user of bot.users) {
if (user.status == "online" && user.bot == false) {
userList.push(user)
}
}
bot.sendMessage(senderId, ':telephone: :arrow_right: Users Found That Meet Search Criteria: ' + userList.length + ' out of ' + bot.users.length + '.'); //Fifth
bot.sendMessage(message, ':telephone: :arrow_right: User Found: ' + userList[Math.floor(Math.random() * userList.length)]); //Sixth
} catch (err) {
bot.sendMessage(message, err)
}
console.log(userList);
console.log(userList.length);
}
}
The code works, it's just the order i was worried about.
Thanks in advance for the help :)
EDIT: I added comments to say what the order should be.
EDIT #2: Clarified Question: I was wondering how i would be able to make the code run in a certain order. And wait for a code prior to run first.
I assume bot.sendMessage makes a network request of some sort to some other system, and the issue you're observing is that those network requests seem to take effect in an unpredictable order. This makes sense, because you're not waiting for one request to finish before starting the next one.
Imagine you opened a web browser and opened two tabs to two different URLs at the same time. Which page would load first? That's basically what your code is doing.
Because I see a .then in one place, I'm going to further assume that bot.sendMessage returns a promise. So go ahead and use the promise to wait for the first request to finish before starting the next one.
Specifically, change this:
bot.sendMessage(senderId, ':telephone: :arrow_right: Users Found That Meet Search Criteria: ' + userList.length + ' out of ' + bot.users.length + '.');
bot.sendMessage(message, ':telephone: :arrow_right: User Found: ' + userList[Math.floor(Math.random() * userList.length)]);
to this:
bot.sendMessage(senderId, ':telephone: :arrow_right: Users Found That Meet Search Criteria: ' + userList.length + ' out of ' + bot.users.length + '.').then(() => {
bot.sendMessage(message, ':telephone: :arrow_right: User Found: ' + userList[Math.floor(Math.random() * userList.length)]);
});
(Ditto with your other messages that you want to happen in a certain order.)
the function you use to send the message runs asynchronously, so you must wait for the end of the first call before invoke the next one (and the rest of the code). smarx gave you a good example about what to do.

Uncaught ScriptError: Invalid argument: EVENT_HANGOUT

This error is received when I try to update a calendar event's title and description. The strange thing is it works on one calendar and not on the other.
Here is a code example
function makeAppointment(eventID, person, calendarID){
Logger.log("eventID:", eventID);
Logger.log("userFolder: " + person);
Logger.log("calendarID: " + calendarID);
var userFolder = findFolder(person);
var calendar = CalendarApp.getCalendarById(calendarID);
var event = calendar.getEventSeriesById(eventID);
var appointments = getAppointments(true, calendarID);
try {
event.setTitle("Interviewee: " + person);
event.setDescription(userFolder.getUrl());
return appointments;
}
catch(e){
Logger.log("There was an issue with setting interview");
}
return appointments;
}
The makeAppointment function is called from the java script side where the relevant information is passed in. But it throws an error on the client side browser console image attached. There are 59 events present on the calendar that creates this issue and 2 on the one that doesn't, I find that to be the only difference between the two.
Thanks for any help provided in solving this issue
The issue was with the type of event. When creating an event, if there is a video call option present for that event, it will throw an error when updating. Removing the video call option will resolve the issue.

YouTube API v3 only displaying 5 results where it should display 7

So, I appear to have hit a problem for which I can't find any relevant information!
Essentially, I have been trying to write this YouTube API call pretty much all day, and when I finally think it is complete I realise that it is only displaying 5 results, and not 7 as it should be doing.
Edit: All 7 do display on the JSON call if I was to visit the $.getJSON('URL') in my browser. The two videos appear to be going missing during the parsing?
The jQuery is as follows:
$.getJSON('https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults=7&playlistId=UUmaGgGFQU_1cv3X4pIUzW9g&key={API_KEY}',function(data){
var i = 0;
$.each(data, function() {
if (typeof(data.items[0]) != "undefined") {
console.log('video exists ' + data.items[i].snippet.title);
title = data.items[i].snippet.title;
description = data.items[i].snippet.description;
videoID = data.items[i].snippet.resourceId.videoId;
if ( i <= 0 ) {
$('#player').append('<div class="first-videocontainer"><h3>'+title+'</h3><iframe width="1120" height="630" src="https://www.youtube.com/embed/'+videoID+'" frameborder="0" allowfullscreen></iframe></div>');
}
else {
$('#player').append('<div class="videocontainer"><h3>'+title+'</h3><iframe width="365" height="205" src="https://www.youtube.com/embed/'+videoID+'" frameborder="0" allowfullscreen></iframe></div>');
}
console.log(i);
i++;
} else {
console.log('video not exists');
}
});
});
I have set the maxResults=7, as I believe this is the only parameter available using APIv3(?).
I'm receiving these errors in the log too, though from Googling them I don't even know if they're of any help because I certainly couldn't find anything constructive from them:
GET chrome-extension://fjhoaacokmgbjemoflkofnenfaiekifl/cast_sender.js net::ERR_FAILED
XHR failed loading: GET "chrome-extension://fjhoaacokmgbjemoflkofnenfaiekifl/cast_sender.js".
So I'm wondering if it's something simple in the jQuery I've just overlooked, or whether my API call is just terrible. This is the first time I've tried to work with this!
Any help is appreciated.
Edit 2: It looks as though it is possibly returning the default value and ignoring my parameter? However, if I set maxResults=4 it does listen.
Documentation: https://developers.google.com/youtube/v3/docs/videos/list#id
"The maxResults parameter specifies the maximum number of items that should be returned in the result set.
Note: This parameter is supported for use in conjunction with the myRating parameter, but it is not supported for use in conjunction with the id parameter. Acceptable values are 1 to 50, inclusive. The default value is 5."
I know i'm late in reply but use this url
https://www.googleapis.com/youtube/v3/search?part=snippet&channelId={channelId}&maxResults=50&key={apikey}
Happy coading

Categories

Resources