Array not found

I swear, this is getting in my nerves and I don’t know how to fix this error:
“[SAFE MODE] Exception caught and saved to data.ERROR: System.ArgumentException: The provided json is not a valid object or array”

The response code is null, why is the stacker’s status changing to ERROR when an array from a parse block isn’t found instead of just ignoring the fact it wasn’t found and continue with the same SUCCESS status?
How can I stop this from happening?

Checked it, does not stop the error from happening. Did some digging using ChatAI and this is what it suggested:

" Certainly! Here are a few examples of how you could handle the case where the parsed array is not found:

  1. Use a try-catch block to handle the exception:
try
{
    JArray arr = data["parsedArray"];
    // Do something with the array
}
catch (Exception ex)
{
    // Handle the exception, e.g. by logging it or providing a default value
}

  1. Check if the token exists before accessing it:
if (data["parsedArray"] != null && data["parsedArray"].Type == JTokenType.Array)
{
    JArray arr = data["parsedArray"];
    // Do something with the array
}
else
{
    // Handle the case where the token is not found or is not an array
}

  1. Provide a default value if the token is not found:
JArray arr = data["parsedArray"] as JArray ?? new JArray();
// Do something with the array (which will be an empty array if the token is not found)

Note that the best approach depends on the specific requirements and context of your application, so it’s important to choose the method that makes the most sense for your use case.


However, I think this is an extra addition to something that wasn’t needed in OB1.

I also asked for a few examples in lolicode, this is what it came up with:

  1. Check if an array exists before trying to access it:
IF EXISTS("jsonkey.arraykey") 
BEGIN 
    SET VARIABLE("array", "jsonkey.arraykey") 
END
  1. Check if an object exists before trying to access it:
IF EXISTS("jsonkey.objectkey") 
BEGIN 
    SET VARIABLE("object", "jsonkey.objectkey") 
END
  1. Check if a specific value exists in an array:
IF INDEXOF("jsonkey.arraykey", "value") >= 0
BEGIN
    # Do something
END

Note that in all these examples, “jsonkey” refers to the key in the JSON response containing the array or object you want to access.

can u show the data ur putting into the block

BLOCK:Parse
LABEL:token
input = @data.SOURCE
jToken = “$.data.token”
MODE:Json
=> VAR @token
ENDBLOCK

Be noticed, this happens when either the response code is null/blank nor when it doesn’t find the array itself.

so just add a regular keycheck that marks it as a fail or ban if the source is equal to nothing or does not contain a part of the array