Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

when cloud code res.error("Error message") the server crash #163

Closed
ynl opened this issue Feb 2, 2016 · 5 comments
Closed

when cloud code res.error("Error message") the server crash #163

ynl opened this issue Feb 2, 2016 · 5 comments
Labels
type:bug Impaired feature or lacking behavior that is likely assumed

Comments

@ynl
Copy link

ynl commented Feb 2, 2016

when cloud code res.error("Error message") the server crash,handleParseErrors not work

@gfosco
Copy link
Contributor

gfosco commented Feb 2, 2016

Can you provide your function? I believe the error callback is being tested already..

@ynl
Copy link
Author

ynl commented Feb 2, 2016

cloud/main.js

var Parse = require('parse/node').Parse;
Parse.initialize("myAppId", "myClientKey");
Parse.serverURL="http://127.0.0.1:1337/parse";
Parse.Cloud.beforeSave("Photo", function (request, response) {
    var imageOSSKey = request.object.get("imageOSSKey");
    var photoQuery = new Parse.Query("Photo");

    if(!request.original) {
        photoQuery.equalTo("imageOSSKey", imageOSSKey);
        photoQuery.find().then(function (results) {
            if (results && results.length > 0) {
                //when image is uploaded, show error ,this line cause server crash
                response.error("image is uploaded");
            } else {
               //do other thing
            }
        }, function (error) {
            response.error(error);
        });
    }else{
        response.success();
    }
});
/Users/linyi/ynltech/HouseShow-express/node_modules/parse-server/triggers.js:60
      throw new Parse.Error(Parse.Error.SCRIPT_FAILED, error);
      ^
[object Object]

app.js

var express=require("express");
var ParseServer=require('parse-server').ParseServer;
var app=express();
var https=require('https');
var fs=require('fs');

var api=new ParseServer({
    databaseURI:'mongodb://127.0.0.1:27017/test',
    cloud:'/Users/linyi/ynltech/HouseShow-express/cloud/main.js',
    appId:'myAppId',
    masterKey:'myMasterKey',
    clientKey:'myClientKey',
    fileKey:'optionalFileKey',
    javascriptKey:'myClientKey'
});

app.use('/parse',api);

app.get('/',function(req,res){
    res.status(200).send('Express is running here.');
});

var port=process.env.PORT||1337;
app.listen(port,function(){
    console.log('parse-server-example running on port '+ port);
});

@ghost
Copy link

ghost commented Feb 2, 2016

You don't need to initialize Parse in cloud/main.js, remove:

var Parse = require('parse/node').Parse;
Parse.initialize("myAppId", "myClientKey");
Parse.serverURL="http://127.0.0.1:1337/parse";

@gfosco
Copy link
Contributor

gfosco commented Feb 2, 2016

True.. it's actually important that you don't re-define Parse, it's set as a global.

Unless you're doing it elsewhere, leave just this:

Parse.serverURL = 'http://126.0.0.1:1337/parse';

But I think this could still be a valid issue with response.error

@ynl
Copy link
Author

ynl commented Feb 2, 2016

Change code to below ,response.error still make the server crash

Parse.serverURL="http://127.0.0.1:1337/parse";
Parse.Cloud.beforeSave("Photo", function (request, response) {
    var imageOSSKey = request.object.get("imageOSSKey");
    var photoQuery = new Parse.Query("Photo");

    if(!request.original) {
        photoQuery.equalTo("imageOSSKey", imageOSSKey);
        photoQuery.find().then(function (results) {
            if (results && results.length > 0) {
                response.error("image is uploaded");
                //throw new Parse.Error(10012,"image is uploaded");
            } else {
               //do other thing
            }
        }, function (error) {
            response.error(error);
        });
    }else{
        response.success();
    }
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug Impaired feature or lacking behavior that is likely assumed
Projects
None yet
Development

No branches or pull requests

3 participants