Sign In Register

How can we help you today?

Start a new topic
Answered

hasScriptErrors - doesn't detect INSUFFICIENT_FUNDS?

 

 I was trying to make a purchase via BuyVirtualGoodsRequest. 


I have this Cloud Code set up on BuyVirtualGoodsResponse:

 

// ====================================================================================================
//
// Cloud Code for BuyVirtualGoodResponse, write your code here to customise the GameSparks platform.
//
// For details of the GameSparks Cloud Code API see https://portal.gamesparks.net/docs.htm			
//
// ====================================================================================================
require("EWL_UTIL");
var errors = Spark.hasScriptErrors();
var errors2 = Spark.getData().error;

if(!errors) {
    EWL_UTIL_autoConsumePurchase(Spark.getData().boughtItems);    
} 


For this response: 

{
 "@class": ".BuyVirtualGoodResponse",
 "error": {
  "currency1": "INSUFFICIENT_FUNDS"
 }
}

 

hasScriptErrors() returns false.


Does hasScriptErrors not detect this error? Should I not be using hasScriptErrors?


Ryan


Best Answer

Hi Ryan,


Yes you are a little off here. hasScriptErrors() will detect if any scriptErrors have been set during the script. The above error is a system error, not one set by the user. So hasScriptErrors() will always return false in the above scenario. The following will grab that particular error.


Spark.getData().error.currency1

  

You should be then able to handle it accordingly.


Thanks,

Liam


Answer

Hi Ryan,


Yes you are a little off here. hasScriptErrors() will detect if any scriptErrors have been set during the script. The above error is a system error, not one set by the user. So hasScriptErrors() will always return false in the above scenario. The following will grab that particular error.


Spark.getData().error.currency1

  

You should be then able to handle it accordingly.


Thanks,

Liam

Thanks Liam.


Are all system level errors always hung off of "error"? Or more simply is this an appropriate way to check for system errors?  

var hasSystemErrors = (Spark.getData().error != undefined);

  

Hi Ryan,


Yes the system "errors" will come back in an error object accompanied by the appropriate error code in the form of a key value pair. So if we take an AuthenticationRequest and put in details we know are incorrect we'll get the following error in response.


"error": {
  "DETAILS": "UNRECOGNISED"
 }

 

So your check should suffice here. If you have any further questions just let us know.


Thanks,

Liam

Login to post a comment