Parse.com Failed with: ReferenceError - javascript

I am trying to run the following parse background job in Cloud Code
Parse.Cloud.job("sendAlert", function(sendAlert) {
Parse.Push.send({
data: {
"content-available": 1,
}
}, {
success: function() {
status.success("Push Worked!!!");
},
error: function(error) {
status.error("Uh oh, something went wrong.");
}
});
});
with the intended result of, when it is run, a "transparent" (not seen by users, but seen by the app) push being sent to users.
When I run it, I get the error
Jobs:
sendAlert
E2015-02-20T19:17:22.637Z] v17: Ran job sendAlert with:
Input: {}
Failed with: ReferenceError: status is not defined
at Object.Parse.Push.send.error (main.js:12:5)
at Parse.js:2:7940
at f (Parse.js:2:6852)
at Parse.js:2:6344
at Array.forEach (native)
at Object.x.each.x.forEach [as _arrayEach] (Parse.js:1:661)
at c.extend.reject (Parse.js:2:6297)
at Parse.js:2:6956
at f (Parse.js:2:6852)
at Parse.js:2:7386
in the log. What am I doing wrong? Thanks, and appreciate it - total Parse novice here.

If you look for the word status in your code, you will see that you haven't declared it anywhere. A variable named status can't just come out of nowhere, so that's why you're getting a ReferenceError.
According to the documentation, the second parameter passed into the Parse.Cloud.job() callback is a JobStatus object with error and success methods, so it seems that's what you're trying to use:
// declare it here ---------v
Parse.Cloud.job("sendAlert", function(sendAlert, status) {
Parse.Push.send({
data: {
"content-available": 1,
}
}, {
success: function() {
status.success("Push Worked!!!");
},
error: function(error) {
status.error("Uh oh, something went wrong.");
}
});
});

Related

Test fail when using Cypress session

I have the following code:
export function backofficeAuthenticate(username, password) {
cy.session(['Login'], () => {
cy.request({
log: false,
method: 'POST',
url: getBackUrl('/login.htm'),
qs: {
redir: getBackUrl('/back'),
},
followRedirect: false,
body: {
'Login_login-email': username,
'Login_login-password': password,
'action[Login_login:login]': 'login',
},
});
});}
And I am calling a function to login like that:
export function loginWithAdmin() {
backofficeAuthenticate(Cypress.env('WEB_LOGIN_USERNAME'), Cypress.env('WEB_LOGIN_PASSWORD'));
}
My code in the test is:
import { loginWithAdmin, httpAuthentication } from '../../cypress/support/bestreviews.js';
describe('Dashboard types quick smoke', () => {
const endpoints = [
'/dashboard',
'/dashboard/articles',
'/dashboard/archive',
'/dashboard/syndicated',
'/dashboard/tribunearticles',
'/dashboard/giftguides',
'/dashboard/blogposts',
];
endpoints.forEach((endpoint) => {
it(endpoint, () => {
cy.visitBackOffice(endpoint);
httpAuthentication();
loginWithAdmin();
cy.checkErrorFree();
cy.get('.dashboard-entries').should('exist');
cy.get('[data-content="topic-info"]').should('exist');
});
});
});
After I execute the code, I always got an error:
(uncaught exception) TypeError: Cannot read properties of null
(reading 'style') TypeError The following error originated from your
application code, not from Cypress.
Cannot read properties of null (reading 'style')
When Cypress detects uncaught errors originating from your application
it will automatically fail the current test.
This behavior is configurable, and you can choose to turn this off by
listening to the uncaught:exception event.Learn more
Does anyone know what I am missing? I think the problem is with cypress session, but not sure how to proceed...
To make sure that cypress catches exceptions generated from your application you can add this in cypress/support/e2e.js
Cypress.on('uncaught:exception', (err, runnable) => {
// returning false here prevents Cypress from
// failing the test
return false
})
Note: One thing to note is that if you add this, cypress will not catch exceptions generated from your application, which is not a good practice, because you want your tests to catch exceptions.

Sending arguments to function as response - why not coming?

Recently I came up that in JS list of arguments is send to another function this way - am I wrong?
func(parameters.response.items)
Code
Request('friends.get', {fields: 'photo_100', count: 5, v: 5.95}, function(data) {
console.log(data);
Draw(data.response.items);
})
function Draw(friends) {
$('#some').html(friends[1].id);
}
The whole proyect is available on http://77.246.157.26/
Error in browser console TypeError: friends[1] is undefined
but console.log() prints all correctly and completely
Went to your site, checked it real quick.
The data from your AJAX call is getting an error..
jQuery33105943325674648605_1558658520581({"error":{"error_code":5,"error_msg":"User authorization failed: access_token was given to another ip address.","request_params":[{"key":"oauth","value":"1"},{"key":"method","value":"friends.get"},{"key":"fields","value":"photo_100"},{"key":"count","value":"5"},{"key":"v","value":"5.95"},{"key":"callback","value":"jQuery33105943325674648605_1558658520581"},{"key":"_","value":"1558658520582"}]}});
Check for error first:
Request('friends.get', {fields: 'photo_100', count: 5, v: 5.95}, function(data) {
if(!data.error) {
//console.log(data);
if(data.response.items) {
Draw(data.response.items);
} else {
console.log("Unexpected json object format.");
}
} else {
alert(data.error.error_msg);
}
});

Stripe Module in Parse Cloud Code Woes

I'm experimenting with the Parse Cloud Code Stripe module and I keep getting a 400 bad request error with the following message:
code: 141, message: "TypeError: Object [object Object] has no method 'i…es.create (stripe.js:157:16)↵ at main.js:11:31
The cloud code runs as long as I don't reference Stripe. The token should be good, as I just created it, although even if it wasn't I would expect a vastly different error message. After tearing my hair out for hours I'm lost for other ideas, and would really, really appreciate any assistance:
var Stripe = require('stripe');
Stripe.initialize('sk_test_oBhEeXgs9x...'); //dots added for confidentiality
Parse.Cloud.define("pay", function(request, response) {
Stripe.Charges.create({
amount: 100 * 10, // $10 expressed in cents
currency: "usd",
card: "tok_3TnIVhEv9..." // dots added for confidentiality
},{
success: function(httpResponse) {
response.success("Purchase made!");
},
error: function(httpResponse) {
response.error("Uh oh, something went wrong");
}
});
});
and my client side code is:
<script>
Parse.initialize("CGqOtFjaHZIs6vG57hAWc...", "j4hDZ7N0s4jwfQIl0t...");
Parse.Cloud.run('pay', {}, {
success: function (result) {
console.log(result);
},
error: function (error) {
console.log(error);
}
});
</script>
I had same problem. I reverted to 1.5.0 using: parse jssdk 1.5.0 in the project directory in the terminal. That fixed it for me.

Internal Server Error when using Meteor.loginWithFacebook

Using the service-configuration and accounts-facebook packages, after clicking on the facebook button and logging in from the Facebook authorization window that pops up, we're getting an Internal server error when performing a Meteor.loginWithFacebook.
This was tested on a very basic example, what is causing this error?
Template.login.events({
'click .btn-facebook': function (ev) {
Meteor.loginWithFacebook({}, function(error) {
if(error) {
throw new Meteor.Error('Facebook login failed: ', error);
}
})
}
});
/server/lib/config/social.js
Meteor.startup(function() {
ServiceConfiguration.configurations.update(
{ service: "facebook" },
{ $set: {
appId: "xxx",
secret: "xxx"
}
},
{ upsert: true }
);
})
Error (server side)
Exception while invoking method 'login' undefined
Error (client side)
Error: Internal server error [500]
at _.extend._livedata_result (http://localhost:3000/packages/ddp.js?d1840d3ba04c65ffade261f362e26699b7509706:4964:23)
at onMessage (http://localhost:3000/packages/ddp.js?d1840d3ba04c65ffade261f362e26699b7509706:3725:12)
at http://localhost:3000/packages/ddp.js?d1840d3ba04c65ffade261f362e26699b7509706:2717:11
at Array.forEach (native)
at Function._.each._.forEach (http://localhost:3000/packages/underscore.js?0a80a8623e1b40b5df5a05582f288ddd586eaa18:156:11)
at _.extend._launchConnection.self.socket.onmessage (http://localhost:3000/packages/ddp.js?d1840d3ba04c65ffade261f362e26699b7509706:2716:11)
at REventTarget.dispatchEvent (http://localhost:3000/packages/ddp.js?d1840d3ba04c65ffade261f362e26699b7509706:156:22)
at SockJS._dispatchMessage (http://localhost:3000/packages/ddp.js?d1840d3ba04c65ffade261f362e26699b7509706:1141:10)
at SockJS._didMessage (http://localhost:3000/packages/ddp.js?d1840d3ba04c65ffade261f362e26699b7509706:1199:18)
at WebSocket.SockJS.websocket.that.ws.onmessage (http://localhost:3000/packages/ddp.js?d1840d3ba04c65ffade261f362e26699b7509706:1346:17)
I had the same issue, and solved it like this :
After checking that you have configured your schema as described here :
Schema.User = new SimpleSchema({
_id: {
type: String
}
...
});
You should add the second part into an Accounts.onCreateUser like this, into server/accounts.js for example :
Accounts.onCreateUser(function (options, user) {
if (user.services.facebook) {
user.emails = [{
address: user.services.facebook.email,
verified: true
}];
}
return user;
});
It will append the facebook email to the newly created account. The error should disapear.

Server side account creation error

I have been trying to get server side account user creating to work but I have come across an issue with the check() method I am using server side. (I am using simple-schema for this)
When the password is empty, this causes check() to throw an error, and rightly so. However, this is a server-side error and I am not quite sure how to propagate this to the client to be caught and dealth with.
The exception that I can see from my browser console is as follows:
Exception while simulating the effect of invoking 'createUserAccount' Meteor.makeErrorType.errorClass {message: "Match error: One or more properties do not match the schema.", path: "", sanitizedError: Meteor.makeErrorType.errorClass, errorType: "Match.Error", stack: (...)…} Error: Match error: One or more properties do not match the schema.
at SimpleSchema.condition (http://localhost:3000/packages/aldeed_simple-schema.js?8fda161c43c0ba62801a10b0dfcc3eab75c6db88:2450:11)
at checkSubtree (http://localhost:3000/packages/check.js?ac81167b8513b85b926c167bba423981b0c4cf9c:255:17)
at check (http://localhost:3000/packages/check.js?ac81167b8513b85b926c167bba423981b0c4cf9c:67:5)
at Meteor.methods.createUserAccount (http://localhost:3000/both/methods/accounts.js?c418120e76666f0ca774a281caafc39bc2c3a59d:4:27)
at http://localhost:3000/packages/ddp.js?41b62dcceb3ce0de6ca79c6aed088cccde6a44d8:4244:25
at _.extend.withValue (http://localhost:3000/packages/meteor.js?81e2f06cff198adaa81b3bc09fc4f3728b7370ec:949:17)
at _.extend.apply (http://localhost:3000/packages/ddp.js?41b62dcceb3ce0de6ca79c6aed088cccde6a44d8:4235:54)
at _.extend.call (http://localhost:3000/packages/ddp.js?41b62dcceb3ce0de6ca79c6aed088cccde6a44d8:4113:17)
at Object.Template.PasswordRegister.events.submit form (http://localhost:3000/client/views/shared/accounts/accounts.js?ac573d92938a2b3d6107ea19e50065f7ac5d41b3:36:20)
at null. (http://localhost:3000/packages/blaze.js?efa68f65e67544b5a05509804bf97e2c91ce75eb:3147:18)
Here is how my client code looks like :
Template.PasswordRegister.events({
'submit form': function(event, template) {
event.preventDefault();
var user = {
email: template.find('#email').value,
password: template.find('#password').value
};
Meteor.call('createUserAccount', user, function(error) {
if (error) {
console.log("CONSOLE : " + error);
//TODO DO SOMETHING
// return alert(error.reason);
} else {
Meteor.loginWithPassword(user.email, user.password, function(error) {
if (error) {
console.log("CONSOLE : " + error);
//TODO DO SOMETHING
// return alert(error.reason);
}
});
}
});
}
});
and here is my server side code:
Meteor.methods({
createUserAccount: function(user) {
// Important server-side check for security and data integrity
check(user, Schema.registration);
var email = user.email;
var password = user.password;
this.unblock();
return Accounts.createUser({
email: email,
password: password
});
}
});
I've tried wrapping client-side code with a normal try catch block but didn't make any difference; that console error still shows.
As the error message says, you have a method stub for 'createUserAccount' defined on the client. It is that client stub that is throwing the exception.
Wrap the method shown with if (Meteor.isServer) to keep it from running on the client.
if (Meteor.isServer ){
Meteor.methods({
createUserAccount: function (user) { ... }
});
}
If that doesn't work search your project for the client code defining the method stub.
To clarify what is happening I have made a meteorpad with a method incorrectly stubbed on the client that throws the error you see in the browser console. I have then added a second method, 'creatUserAccount1', which is only defined on server. When this second method is called, its error is handled by callback and does not cause an exception. I think that is the behaviour you want.

Categories