diff --git a/src/messenger/webim/js/compiled/mibewapi.js b/src/messenger/webim/js/compiled/mibewapi.js index 7d8ab6a5..988493e5 100644 --- a/src/messenger/webim/js/compiled/mibewapi.js +++ b/src/messenger/webim/js/compiled/mibewapi.js @@ -18,4 +18,4 @@ MibewAPIInteraction.prototype.getObligatoryArgumentsDefaults=function(a){var b={ function MibewAPIExecutionContext(){this.returnValues={};this.functionsResults=[]} MibewAPIExecutionContext.prototype.getArgumentsList=function(a){var b=a.arguments,c=a.arguments.references,d,f,e;for(e in c)if(c.hasOwnProperty(e)){f=c[e];if("undefined"==typeof this.functionsResults[f-1])throw Error("Wrong reference in '"+a["function"]+"' function. Function #"+f+" does not call yet.");if("undefined"==typeof b[e]||""==b[e])throw Error("Wrong reference in '"+a["function"]+"' function. Empty '"+e+"' argument.");d=b[e];if("undefined"==typeof this.functionsResults[f-1][d])throw Error("Wrong reference in '"+ a["function"]+"' function. There is no '"+d+"' argument in #"+f+" function results");b[e]=this.functionsResults[f-1][d]}return b};MibewAPIExecutionContext.prototype.getResults=function(){return this.returnValues}; -MibewAPIExecutionContext.prototype.storeFunctionResults=function(a,b){var c,d;for(d in a.arguments["return"])if(a.arguments["return"].hasOwnProperty(d)){c=a.arguments["return"][d];if("undefined"==typeof b[d])throw Error("Variable with name '"+d+"' is undefined in the results of the '"+a["function"]+"' function");this.returnValues[c]=b[d]}this.functionsResults.push(b)}; +MibewAPIExecutionContext.prototype.storeFunctionResults=function(a,b){var c;if(b.errorCode)this.returnValues.errorCode=b.errorCode,this.returnValues.errorMessage=b.errorMessage||"";else for(var d in a.arguments["return"])if(a.arguments["return"].hasOwnProperty(d)){c=a.arguments["return"][d];if("undefined"==typeof b[d])throw Error("Variable with name '"+d+"' is undefined in the results of the '"+a["function"]+"' function");this.returnValues[c]=b[d]}this.functionsResults.push(b)}; diff --git a/src/messenger/webim/js/source/mibewapi.js b/src/messenger/webim/js/source/mibewapi.js index c4fd445a..96cea319 100644 --- a/src/messenger/webim/js/source/mibewapi.js +++ b/src/messenger/webim/js/source/mibewapi.js @@ -470,20 +470,28 @@ MibewAPIExecutionContext.prototype.getResults = function(){ */ MibewAPIExecutionContext.prototype.storeFunctionResults = function(functionObject, results) { var alias; - // Add value to request results - for (var argName in functionObject.arguments["return"]) { - if (! functionObject.arguments["return"].hasOwnProperty(argName)) { - continue; + // Check if function return correct results + if (!results.errorCode) { + // Add value to request results + for (var argName in functionObject.arguments["return"]) { + if (! functionObject.arguments["return"].hasOwnProperty(argName)) { + continue; + } + alias = functionObject.arguments["return"][argName]; + if (typeof results[argName] == "undefined") { + throw new Error( + "Variable with name '" + argName + "' is undefined in " + + "the results of the '" + functionObject['function'] + + "' function" + ); + } + this.returnValues[alias] = results[argName]; } - alias = functionObject.arguments["return"][argName]; - if (typeof results[argName] == "undefined") { - throw new Error( - "Variable with name '" + argName + "' is undefined in " + - "the results of the '" + functionObject['function'] + - "' function" - ); - } - this.returnValues[alias] = results[argName]; + } else { + // Something went wrong during function execution + // Store error code and error message + this.returnValues.errorCode = results.errorCode; + this.returnValues.errorMessage = results.errorMessage || ''; } // Store function results in execution context this.functionsResults.push(results); diff --git a/src/messenger/webim/libs/classes/mibew_api_execution_context.php b/src/messenger/webim/libs/classes/mibew_api_execution_context.php index 3aefe686..7a924426 100644 --- a/src/messenger/webim/libs/classes/mibew_api_execution_context.php +++ b/src/messenger/webim/libs/classes/mibew_api_execution_context.php @@ -98,18 +98,29 @@ Class MibewAPIExecutionContext { * @throws MibewAPIException */ public function storeFunctionResults ($function, $results) { - // Add value to request results - foreach ($function['arguments']['return'] as $name => $alias) { - if (! isset($results[$name])) { - // Value that defined in 'return' argument is undefined - throw new MibewAPIException( - "Variable with name '{$name}' is undefined in the " . - "results of the '{$function['function']}' function", - MibewAPIException::VARIABLE_IS_UNDEFINED_IN_RESULT - ); + // Check if function return correct results + if (empty($results['errorCode'])) { + // Add value to request results + foreach ($function['arguments']['return'] as $name => $alias) { + if (! isset($results[$name])) { + // Value that defined in 'return' argument is undefined + throw new MibewAPIException( + "Variable with name '{$name}' is undefined in the " . + "results of the '{$function['function']}' function", + MibewAPIException::VARIABLE_IS_UNDEFINED_IN_RESULT + ); + } + $this->return[$alias] = $results[$name]; } - $this->return[$alias] = $results[$name]; + } else { + // Something went wrong during function execution + // Store error code and error message + $this->return['errorCode'] = $results['errorCode']; + $this->return['errorMessage'] = empty($results['errorMessage']) + ? '' + : $results['errorMessage']; } + // Store function results in execution context $this->functions_results[] = $results; }