returnError (function)

Last updated: Fri, May 26, 2023 9:16 am
Return to Knowledgebase


The returnError function in UserSpice is a custom function used to return an error response in JSON format and terminate the script execution.




# Parameter Data Type Required Description
1 $errorMsg string Yes The error message to be included in the response.

Further Documentation:

$errorMsg = "An error occurred.";


In the example above, the returnError function is called with the $errorMsg variable as the argument. The function constructs an error response in JSON format with the provided error message. It then exits the script execution by calling exit() function with the JSON-encoded response.

The resulting response will be:
"success": true,
"error": true,
"errorMsg": "An error occurred."

Note that the returnError function is typically used when encountering an error situation to provide a standardized error response format and halt the script execution.