Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Handling errors using Parse.com Cloud Code and javascript API

What is the best way to handle errors using Parse.com Cloud Code. I'm able to use console.log and Firebug to see when Parse Cloud Code throws an error, but I need some help with how to notify the client that something went wrong. Some sample code from both sides would really be great -- Cloud Code and client side javascript code.

like image 442
hypermiler Avatar asked Oct 03 '22 00:10

hypermiler


1 Answers

I preferred it this way -

On Cloud Code make one ErrorHandler.JS file -

exports.sendError = function(response, message, data) {
    console.log("Message - " +  message + " Data - " + JSON.stringify(data)); // To print LOG on Cloud Code
    // Moreover you can use any of - "console.error/warn" - as mentioned - https://parse.com/docs/cloud_code_guide#logging
    response.error({
        status      : false, // Indicates EXECUTION STATUS - I am using "successHandler" also & using STATUS as "true" 
        message     : message, // Refers to Error Message
        data        : data || {} // Error Object or your customized Object
    });
}

& client side you will have all data to print if you want or you can just show alert message to the Users.

More over it's preferred to check both SERVER side as well as CLIENT side LOG for DEVELOPING purpose because PARSE Cloud Code stores only last 100 messages in LOG.

& In order to implement proper LOGGING you must made some custom procedures with proper storage structure in terms of CLASS.

like image 156
Vintesh Avatar answered Oct 13 '22 10:10

Vintesh