Can't call Cloud Code from JavaScript - javascript

I have a JavaScript client which connects to my local Parse server just fine. Login works, Parse.Query works, however calling any Cloud Code function with Parse.Cloud.run does not work -- instead I get the error 100/XMLHttpRequest failed. Calling CC functions from commandline using curl does work, indicating that the overall server setup is correct.
It's obviously a client configuration problem on my part, but I just can't figure out what the problem might be. Client setup is simple enough:
Parse.initialize('myappid');
Parse.serverURL = 'http://localhost:1337/parse';
Any ideas?

The problem was that my CC funtion requires a Date argument but I passed in a moment object... now I converted it to Date and all is well again. Silly me, but 100/XMLHttpRequest failed/ConnectionFailed is also a very misleading error message for this!

Related

ApplicationInsightsTelemetryClient not logging bot identifiers

I'm using the JavaScript version of the botframework. I've followed the documentation to enable telemetry logging in Application Insights. When I access the logs I can see that custom events are being logged.
The issue is that the bot specific identifiers, such as user_Id, session_Id and conversation_Id are not being logged. This can be seen in the screen capture below
In the applicationInsightsTelemetryClient.js file there is a function called addBotIdentifiers. As far as I can tell, it is this function that is responsible for adding the bot specific identifiers.
The first lines of the function look like this:
function addBotIdentifiers(envelope, context) {
if (context.correlationContext && context.correlationContext.activity) {
Inspecting this function shows that the context argument is always null.
This leads me to my questions.
Why is it null?
Any suggestions on what I need to do to have it set appropriately?
Update
In digging into this further it appears the code starting at line 26 in the applicationInsightsTelemetryClient.js file isn't being called. Could this be the cause of the missing context later on in the addBotIdentifiers function?
Looks like the documentation has a missing line in step 7. We will correct the document ASAP. Meanwhile, please add the below in your index.js following https://github.com/microsoft/BotBuilder-Samples/blob/main/samples/javascript_nodejs/21.corebot-app-insights/index.js#L113
// Enable the Application Insights middleware, which helps correlate all activity
// based on the incoming request.
server.use(restify.plugins.bodyParser());
Further investigation has shown what the issue was. It's not immediately obvious.
I compared the code in my index.js file with the one in the 21.corebot-app-insights BotBuilder sample.
Note that the setup of the Restify server happens after the creation of the adapter bot adapter. It is also after the configuration of the main dialog and the middleware.
In my code the setup of the Restify server and the bot adatper / dialogs was intermingled. This appears to have been the cause of the problem.
The main lesson here for me, and for anyone who stumbles across this post later, is that the setup of the Restify server should be at the end of the index.js file. To ensure all of the bot framework is setup first.

Firebase function not fetching config variable

I'm trying to write a firebase function to send a transactional e-mail with SendGrid whenever it gets triggered by a HTTP request, but at the moment I'm having real difficulty getting the function to be able to access the configuration variables that I've set with the sendgrid key which is obviously a real problem...
I've set the config variable with the below command:
$ firebase functions:config:set sendgrid.key="KEY_HERE"
When I run firebase functions:config:get to list all the config values, it returns the correct value in the terminal:
{
"sendgrid": {
"key": "KEY_HERE"
}
}
But when I try to access it from my function (tried with both TypeScript & Vanilla JS setups), functions.config() just returns an empty object.
Has anyone encountered & solved this issue before, or am I doing something wrong? In either case, if anyone could give me a pointer then that'd be much appreciated!
Edit the first
I have deployed the function, and called it while hosted and looking at the logs, you can see the correct values. However, I still see the problem when I call the function when served locally on my machine for testing, which is a problem as I'd like to not have to deploy a function just to see if it works...

Stripe.js was not loaded correctly

I'm loading stripe into my payment page like so:
<script src="https://js.stripe.com/v3/"></script>
This works perfectly in my local test environment but in production, the following console error appears:
Uncaught Error: It looks like Stripe.js was not loaded correctly
at new e (controller-84824401a25a5595fc578f767b4d5c27.js:1)
at controller-84824401a25a5595fc578f767b4d5c27.js:1
at Object.bnjt (controller-84824401a25a5595fc578f767b4d5c27.js:1)
at t (shared-d3604a85e14ef273096e09821a0e4c2a.js:1)
at Object.3 (controller-84824401a25a5595fc578f767b4d5c27.js:1)
at t (shared-d3604a85e14ef273096e09821a0e4c2a.js:1)
at window.webpackJsonp (shared-d3604a85e14ef273096e09821a0e4c2a.js:1)
at controller-84824401a25a5595fc578f767b4d5c27.js:1
I can't work out what might be causing the error. I'm using HTTPS in production and can see the JS file source downloading successfully. Any tips?
Solved following advice from #NathanCasebolt. SO mods deleted his original answer:
“For me, the resolution to this error was as simple as spell-checking
my variables. In my backend server code, one of my variables was
wrongly capitalized. Since the misspelled variable was part of the
function that retrieves my publishable key, the key returned from the
server as null. This, in turn, disrupted creation of the Stripe object
and threw this error. If I were you, I'd check to make sure (1) that
the publishable key on your frontend matches the publishable key in
your dashboard, and (2) that you're not doing anything that might
disrupt serving this key to Stripe.”
The StackOverflow mods felt this didn’t answer the question and
required too much clarification. So, to clarify, the problem for me
was this line:
var stripe = Stripe(‘{PUBLISHABLE_KEY}’);
I set things up to retrieve my publishable keys from my server, to
give me more flexibility in switching between test keys and live keys.
Since my one of my server variables was wrong, I was providing Stripe
with a bad key (no key, really), and that’s what threw the error. This
is why I suggest you check the publishable key you’re using to create
the Stripe object, to make sure that the one you’re using to create
the object is there, and that it matches the publishable key you have
on your Stripe dashboard."
In my case, this is exactly what I'd done wrong: provided an empty publishable key when initialising Stripe. Ultimately a very simple mistake compounded Stripe's obtuse error message.

Cloud Code function running twice

I have written a cloud function that is working well.
Sometimes this function is being executed more than one time for the same user (I made sure that only one request is being requested from the client android app).
After some debugging I noticed that this problem happens if the connection is bad. I may be or may not be correct.
How to overcome such an issue?
As in the comments I also don't believe the client SDKs would duplicate a Cloud Function call on a bad connection. The expected behaviour would be for them to throw a network-related exception on the client side and not call it again. A problem would arise if the Cloud Function runs successfully and the client is only unable to get the result back.
I can think of the following solutions, with no more details about the Cloud Function itself:
Try to make the function idempotent - Meaning that even if it runs twice the end result is the same, assuming the same input/parameters.
Cache the results and manually throttle the function - This is more complicated, and is only needed if the network problem persists and you can't work around eliminating the side effects of the function. You would have to create another Class to cache the results of the function (maybe keyed by the parameters) and returning the same result with no computation and side effects.

google script : IO error when deserializing continuation

I wrote a script that adds a function in a Google spreadsheet that was working well. From today, I get an error:
IO error when deserializing continuation.
This appears after a call to Ui.alert or Ui.prompt. I tried to add sleep after the calls, but it doesn’t work. This is a sample of code:
ui.alert( "ERROR. !");
Utilities.sleep(1000);
return;
I also had the same problem using a script to merge mail from spreadshhet.
I saw a post from year 2014 that explains this is a error server at Google end and ot in any coe of any script.
Next day the problem was solved by itself. It's a problem from Google...
I also saw this error for the first time today. I got the script working again by running another function that worked, when I went back and executed the problematic function it was then working again.
In another case, a user reported they were getting this error. Closing and re-opening the spreadsheet helped the affected user.
Probably a Google issue and not something directly related to your code.
Could system latency (PC + Internet) be the cause? This would explain apparent randomness, and be fixable on Google's end by increasing the timeout associated with the Browser.msgbox I/O process.

Categories

Resources