Sign In Register

How can we help you today?

Start a new topic
Answered

Throw Non-FATAL Exception with INFO log level entry

Hi all,


I want to throw an exception in a specific situation. My problem is that in the log database, the log level has the type FATAL. But I want it to be INFO. Is it possible?


 

if(someCondition) {
    throw "error message"; // -> this will be a FATAL log entry; but need INFO
}

 


Best Answer

Hi Artem,


Our database logging is handled with SparkLog. I've linked the relevant tutorial here: https://docs.gamesparks.com/api-documentation/cloud-code-api/utilities/sparklog.html


Hope this helps,

 - Steve


Answer

Hi Artem,


Our database logging is handled with SparkLog. I've linked the relevant tutorial here: https://docs.gamesparks.com/api-documentation/cloud-code-api/utilities/sparklog.html


Hope this helps,

 - Steve

Hi Steve, 


thank you! On the top of that I found a well suited solution for my problem. See below...


 

// ====================================================================================================
//
// Cloud Code for TestException, write your code here to customise the GameSparks platform.
//
// For details of the GameSparks Cloud Code API see https://portal.gamesparks.net/docs.htm			
//
// ====================================================================================================

var throwError = true;

main();

function main() {
    if(throwError) {
        Spark.setScriptError("data", "someData"); // set error message or code
        Spark.setScriptData("data2", {"name" : "someName"}); // add additional data to the response
        Spark.getLog().info("INFO TEST"); // insert log entry at the preferred log level
        return; // cancel further execution of the code
    }
    throw "FATAL Exception"; // will be never called if 'throwError' == true
}

 

Login to post a comment