Fix bug with errorCode in Mibew API execution context

This commit is contained in:
Dmitriy Simushev 2013-02-22 09:12:28 +00:00
parent 8fc9b85bfa
commit 709623dfc5
3 changed files with 43 additions and 24 deletions

View File

@ -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)};

View File

@ -470,6 +470,8 @@ MibewAPIExecutionContext.prototype.getResults = function(){
*/
MibewAPIExecutionContext.prototype.storeFunctionResults = function(functionObject, results) {
var alias;
// 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)) {
@ -485,6 +487,12 @@ MibewAPIExecutionContext.prototype.storeFunctionResults = function(functionObjec
}
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);
}

View File

@ -98,6 +98,8 @@ Class MibewAPIExecutionContext {
* @throws MibewAPIException
*/
public function storeFunctionResults ($function, $results) {
// 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])) {
@ -110,6 +112,15 @@ Class MibewAPIExecutionContext {
}
$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;
}