Parse-server Cloud Code Error 141 Invalid Function - ios

I am running parse-server on Heroku, I am working on implementing a custom cloud code function, however every implementation returns invalid function code: 141, Version:1.12.0
I have successfully gotten the "hello" function to work, including 1 change I made to it:
Parse.Cloud.define('hello', function(req, res) {
console.log("received.........");
res.success('Hi');
});
The custom function I am trying to get working is a simple query to my database:
Parse.Cloud.define("titleQuery", function(request, response) {
var query = new Parse.Query("StudentNotes");
query.equalTo("title", request.params.title);
query.find({
success: function(results) {
console.log("received........." + results);
response.success(results);
},
error: function() {
console.log("received........." + error);
response.error("title lookup failed");
}
});
});
When I run this on iOS with the following code:
PFCloud.callFunctionInBackground("titleQuery", withParameters: ["title": "testTitle"]) {
(response: AnyObject ? , error : NSError ? ) - > Void in
let hello = response // as? String
print(hello)
}
I am querying my database in class "StudentNotes" for object title with the name "testTitle", I know for a fact that that object exists, however due to it throwing error 141 I do not receive anything. Any help would be greatly appreciated.
EDIT2: I have gotten custom cloud functions to work, however I cannot get any queries to my database to work. Can anyone post a confirmed working query that returns an object? Perhaps from the _User table so that I can copy/paste and ensure that my cloud code can access my database?
My process:
I edit the Main.js file and add in my cloud function.
Then i commit & push (successfully)
finally i restart my Heroku server
Then i still get an error 141 invalid function return

I have successfully solved this problem and gotten regular queries to work. The problem was in my Heroku config vars in the dashboard. My server URL was invalid, never changed from the default of "http://yourappname.com/parse/" I have to manually enter "yourappname".

Related

Using Stripe Terminal iOS SDK with Nativescript

I'm attempting to use the Stripe Terminal SDK in the Nativescript plugin seed and test it in the demo-angular app. I'm able to initialize the SDK by setting the connection token provider. When the SDK calls the provider's fetchConnectionToken method, the app crashes with no terminal output when the method calls the SDK-supplied completion handler. Debugging in XCode shows _EXC_BAD_ACCESS code=2.
Relevant code:
iOSFetchConnectionToken(completion: (p1: string, p2: NSError) => void) {
/* No crash if the following two lines are uncommented */
// completion(hardCodedTokenSecret, nullError);
// return;
Http.request({
url: DemoSharedStripeterminalBasic.serverAddress,
method: 'POST',
headers: {
"Content-Type": "application/json",
"Stripe-Public-Key": this.stripeTestKey
},
content: JSON.stringify({
connectedAccountId: this.connectedAccountId
})
}).then(response => {
const result = response.content?.toJSON();
secret = result.secret;
completion(secret, null); // App crashes with no output
})
}
The above function is assigned to the ConnectionTokenProvider's fetchConnectionToken method. I'm able to call the completion handler successfully before the HTTP request (using hardcoded or null values – see the commented lines at the top), but the crash occurs when I invoke the completion handler in the "then" block of the request, using either the returned value from my API server or a hardcoded/null value. Logging out the completion function gives "function () { [native code] }" which indicates that it's properly accessible in memory. I can't figure out where the bad access is coming from or why it's only happening inside the "then" block.
In the sample above, I'm using Nativescript's built in HTTP module, but I've also tried with JS fetch and have the same issue. I've also tried rewriting using async/await with no luck. My API server correctly returns a valid token (I successfully used the same one for the hard-coded token secret), so I know that isn't the issue either. Any help is hugely appreciated, thanks!

difference between fetching page and file in serviceworker

event.respondWith(caches.match(event.request).then(function (response) {
if (response) {
return response;
}
//return fetch(event.reuqest, { credentials: 'include' });
//event.respondWith(fetch(event.request, { credentials: 'include' }));
}));
This is a common code for handling request via serviceworkers , if the url is in cache then return cache response or fetch it from server .
But my doubt is regarding the 2 commented lines , we need to use one of them for fetching the response .
My doubt is, when i use event.respondWith(fetch(event.request, { credentials: 'include' for fetching a page , i get the following error
DOMException: Failed to execute 'respondWith' on 'FetchEvent': The fetch event has already been responded to.
But the page is finally rendered , definitely browser is finally fetching the response , but when i use sam for fetching an image , i get the same error and on top of that the image is not fetched .
if i use the second option that return fetch(event.reuqest, { credentials: 'include' }); , then it works fine for both image as well as page.
I am not able to figure out what is the reason of that error , and also why it is behaving differently for file and page .
My another doubt is , do i actually need the credential parameter here ,i added it because most of the implementations i saw in web have used it,but what i have observed is that the request object already has a credential property with it , now it is not always
include
sometime it is
same-origin
too.
So could it happen that i am actually overriding the actual credential value by adding it .If that is not the case , then there is no difference in including it or not.It does not matter .
But if it is other way around , then we should not overwrite the credential value, which can have bad side effects.
You already have a call to event.respondWith, you don't need to call it twice.
Your first call is going to use the promise returned by:
caches.match(event.request).then(function(response) {
if (response) {
return response;
}
return fetch(event.reuqest, { credentials: 'include' });
})
This promise resolves to:
response, if the request is in the cache;
the promise returned by the call to fetch, otherwise.
The promise returned by fetch will resolve to a response, which is then going to be used by respondWith.

Create New Row in database using Odata

I have an OData Service that is pointing to a table in the database. I want to enter a new record in the table based on the details from user.
I am using the .create method, but the data doesn't seem to get entered in table.
oView=this.getView();
var df = {};
var name = oView.byId("__input3").getValue();
var goal = oView.byId("__area0").getValue();
df.NAME = name;
df.GOAL = goal;
df.TYPE = "type";
df.THEME = "Theme";
var oModel1= new sap.ui.model.odata.ODataModel("/GDH_OData/services/df.xsodata/");
oModel1.create('/Df', df, null, function() {
alert("SUCCESS");
}, function() {
alert("FAIL");
});
Please help where I am going wrong
you're not giving a lot of info, here...
what is the result of your create call ? SUCCESS or FAIL ? if the later, what is the error message returned ? the following error function can help you on this
function(error) {
var message = $(error.response.body).find('message').first().text();
console.log(message);
alert(message);
}
Is the creation code in the backend called (if you put an external breakpoint in your service, do you get the debugger ?) if so, what is the result of debugging step-by-step ?
edit
if there is a "forbidden" response, then you should check the result of transaction su53 for the user. You'll probably have a failed autorization. Then it's just adding the service to your role autorisation.
PS : its better to add your answer to my questions(s) in your question, under a "edit" or "more information" than to put it as another answer. Thus there is only one place to check for the whole problem.
regards
The result is Fail and the error is "Failed to load resource: the server responded with a status of 403 (Forbidden)"

Async API call error

I'm currently trying to call the twitter API using meteor and so far i got this:
updateTotalFoll:function(){
var Twit = Meteor.npmRequire('twit');
var T = new Twit({
consumer_key: 'AWzYAlWFRh9zsownZMg3',
consumer_secret: 'aYpL3zMPfqRgtX1usPQpEREEXVNPfNYna9FiIwTeDYR',
access_token: '4175010201-TEp9qNKO4mvjkj0GMjJFZIbGPYaVv4',
access_token_secret: 'EPpcJyN27E4PvhJpYaTHflNFOv3DuR05kTP2j'
});
var Id2=RandomCenas.findOne({api:"twitter"})._id;
T.get('statuses/user_timeline', { screen_name: 'jeknowledge' }, function (err, data, response){
//console.log(data[0].user.followers_count);
RandomCenas.update(Id2,{$set:{totalFoll:data[0].user.followers_count}});
});
}
with "RandomCenas" being a MongoDB.
What i'm trying to do is updating this collection with the info from the call , but i get this error
Error: Meteor code must always run within a Fiber.
Try wrapping callbacks that you pass to non-Meteor libraries with Meteor.bindEnvironment.
I've searched the web for a way to counter this , but i cant seem to apply the solutions that i came across with.
Any help with how i can deal with this?
try it like that
T.get('statuses/user_timeline', { screen_name: 'jeknowledge' }, Meteor.bindEnvironment(function (err, data, response) {
//console.log(data[0].user.followers_count);
RandomCenas.update(Id2,{$set:{totalFoll:data[0].user.followers_count}});
}));
the reason this is happening is because callback function which you pass it's happening outside the current Meteor's Fiber check the answer Error: Meteor code must always run within a Fiber

Meteor Twitter Help (Meteor NOOB)

I just started learning MeteorJS and after completing the tutorial, I decided to play around with the Twitter API. Initially, I followed this tutorial
http://artsdigital.co/exploring-twitter-api-meteor-js/
Once completing that, what I wanted to do is scrape data from a tweet and display it on the client side.
N/A = proper authentication
Here's the code I've written:
if (Meteor.isClient) {
Session.setDefault('screen_name', 'John');
Template.hello.helpers({
screen_name: function () {
return Session.get('screen_name');
}
});
Template.hello.events({
'click button': function () {
T.get('search/tweets',
{
q: '#UCLA',
count: 1
},
function(err,data,response) {
var user_name = data.statuses[0].users.screen_name;
Session.set('screen_name', user_name);
}
)
}
});
}
if (Meteor.isServer) {
Meteor.startup(function () {
// code to run on server at startup
var Twit = Meteor.npmRequire('twit');
var T = new Twit({
consumer_key: 'N/A', // API key
consumer_secret: 'N/A', // API secret
access_token: 'N/A',
access_token_secret: 'N/A'
});
});
}
What I believe the problem is that, the 'click button' function, the 'T' is seen to be undefined so the compiler doesn't know what that is or where it came. That thought did spark a thought in my mind to move what I have written inside the
if (Meteor.isServer) to if (Meteor.isClient)
But to no avail. It didn't work. What my reasoning is that once Meteor starts, the server starts, so if the server declares the variable T, shouldn't we be able to access it on the client side too?
I'm not sure if my approach is correct/don't know the conventions of Meteor/Meteor NOOB..so if someone could please help me, that will be highly appreciated!
Thanks!
You put a "var" declaration in front of your "T" variable. This binds the scope to the server side context of the app. I bet if you got rid of the var and made "T" global, then you would be able to access it from the client side as well.

Resources