mirror of
				https://github.com/Mibew/java.git
				synced 2025-10-31 18:41:09 +03:00 
			
		
		
		
	Fix bug with errorCode in Mibew API execution context
This commit is contained in:
		
							parent
							
								
									8fc9b85bfa
								
							
						
					
					
						commit
						709623dfc5
					
				| @ -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)}; | ||||
|  | ||||
| @ -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); | ||||
|  | ||||
| @ -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; | ||||
| 	} | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user