Check response data

@param $result
@throws \Exception
190452
private function checkResult($result)
    {
        if ($this->debug) {
            if (in_array($this->format, [self::FORMAT_JSON, self::FORMAT_JSONP])) {
                $result = json_decode($result, true);
            } elseif ($this->format == self::FORMAT_SERIAL) {
                $result = unserialize($result);
            }

            if (is_array($result)) {
                if (isset($result['success']) && $result['success'] == 0 && isset($result['error'])) {
                    throw new \Exception($result['error']);
                }
            }
        }
    }
500927
public function route_respond( $result_data ) {
		// Logic depends on the contents/state of result_data
		if ( !is_null( $result_data ) ) {

			// True response
			if ( $result_data === true ) {
				// True case WITHOUT any returned data
			}
			elseif ( $result_data === false ) {
				// Throw an exception
				throw new InvalidApiParameters();
			}
			else {
				// Prepare our data for response
				$this->response->data = $result_data;
			}

		}
		else {
			// The response is null, throw an exception
			throw new ObjectNotFound();
		}
	}
1341568
final protected function verifyResult($result)
    {
        $returnType = $this->returnType;
        if ($returnType === null) {
            if ($result !== null) {
                throw TypeMismatchException::format(
                        'Invalid return type from action handler %s: expecting null, %s given',
                        get_class($this), Debug::getType($result)
                );
            }

            return $result;
        }

        if (!($result instanceof $returnType)) {
            throw TypeMismatchException::format(
                    'Invalid return value from action handler %s: expecting %s, %s given',
                    get_class($this), $returnType, Debug::getType($result)
            );
        }

        return $result;
    }
514239
public function processResponse()
    {
        // Init results
        $results = [];

        foreach ($this->packets_response as $response) {
            $buffer = new Buffer($response);

            // Figure out what packet response this is for
            $response_type = $buffer->read(6);

            // Figure out which packet response this is
            if (!array_key_exists($response_type, $this->responses)) {
                throw new Exception(__METHOD__ . " response type '" . bin2hex($response_type) . "' is not valid");
            }

            // Now we need to call the proper method
            $results = array_merge(
                $results,
                call_user_func_array([$this, $this->responses[$response_type]], [$buffer])
            );

            unset($buffer);
        }

        return $results;
    }
7157
public function afterExecute($subject, $result)
    {

        try {
            // Pass through the original result if the customer is not logged in or the cart is empty
            if (!$this->shouldRedirectToCartPage()) {
                return $result;
            }

            // Set the flag in session to auto-open Bolt checkout on redirected (shopping cart) page
            $this->setBoltInitiateCheckout();

            // Redirect to shopping cart
            return $this->resultFactory
                ->create(ResultFactory::TYPE_REDIRECT)
                ->setPath(self::SHOPPING_CART_PATH);
        } catch (\Exception $e) {
            // On any exception pass the original result through
            $this->notifyException($e);
            return $result;
        }
    }
637729
private function resultToResponse($result) : Response
	{
		switch (true) {
			// Response object
			case $result instanceof Response:
				return $result;
			// String -> transform to response
			case is_string($result) || is_numeric($result):
				return new Response($result);
			// Array -> transform to json response
			case is_array($result) || is_object($result):
				return new JsonResponse($result);
			default:
				throw new Exception('Invalid route handler return value');
		}
	}
1160717
public function responseIsSuccessfullyWithContainScalarResult($result)
    {
        Assertions::assertEquals(200, $this->response->getStatusCode(), sprintf(
            'Response with error "%s"',
            $this->response->getBody()
        ));

        Assertions::assertTrue(is_null($this->response->getRpcErrorCode()), sprintf(
            'Response with error "%s"',
            $this->response->getBody()
        ));

        Assertions::assertEquals($result, $this->response->getRpcResult(), sprintf(
            'Result must be a contain "%s"',
            $result
        ));
    }
189994
public function fetchResponse($response, $result)
    {
        if ($response) {
            $data = [];
            while ($row = mssql_fetch_array($response)) {
                $data[] = $row;
            }

            return $data;
        }

        return false;
    }
1331717
public function getResponse($result)
    {
        $content = $result->getContent();

        if ($result->headers->get('content-type') == 'application/json'){
            $content = json_decode($result->getContent(),true);
        }

        return array(
          'type' => 'rpc',
          'tid' => $this->tid,
          'action' => $this->action,
          'method' => $this->method,
          'result' => $content
        );
    }
739307
protected function _checkResult($result) {
        $rvalue = true;
        foreach ($result as $socketName => $value) {
            if ($value !== true) {
                Mage::helper('turpentine/debug')->logWarn(
                    'Error in Varnish action result for server [%s]: %s',
                    $socketName, $value );
                $rvalue = false;
            }
        }
        return $rvalue;
    }
521807
public function onResult(\pq\Result $result = null) {
		if ($result && $result->status != \pq\Result::TUPLES_OK) {
			return $result;
		}
		
		$rowset = $this->getRowsetPrototype();
		if (is_callable($rowset)) {
			return $rowset($result);
		} elseif ($rowset) {
			return new $rowset($this, $result);
		}
		
		return $result;
	}
431361
private function returnResponse($result): Response
    {
        if ($result instanceof Response) {
            return $result;
        }

        if (is_array($result)) {
            $result = json_encode($result);
        }

        return new Response(200, [], $result);
    }
1241759
public function serialize($result)
    {
        try {
            // array is serialized as an object {"0":{...},"1":{...},...} when data contains an empty objects
            // we serialize each item because we can assume this bug affects only root array element
            if (is_array($result) && array_keys($result) === range(0, count($result) - 1)) {
                $result = array_map(
                    function ($item) {
                        return $this->serializeContent($item);
                    },
                    $result
                );

                return '['.implode(',', array_filter($result)).']';
            }

            return $this->serializeContent($result);
        } catch (\Exception $e) {
            throw new SerializationException($e);
        }
    }
938038
protected function bindAttr($model, &$result)
    {
        foreach ($this->bindAttr as $key => $attr) {
            $key = is_numeric($key) ? $attr : $key;
            if (isset($result->$key)) {
                throw new Exception('bind attr has exists:' . $key);
            } else {
                $result->setAttr($key, $model ? $model->$attr : null);
            }
        }
    }
155276
private function _CheckErrors($operation, $results)
	{
		if (is_soap_fault($results)) 
			throw new Exception("SOAP Fault: ".$results->faultcode."\n".$results->faultstring."\n", 4);
	}
718502
private function isPoisonedResult($result)
    {
        if ('STATUS:' != substr($result, 0, 7)) {
            return false;
        }

        $parts = explode(':', $result, 3);
        $code  = (int) $parts[1];

        if ($code === 500) {
            return true;
        }

        return false;
    }
556754
public function buildResponse($result) {
        if ($result === false) {
            if ($curlErrorNumber = curl_errno($this->_ch)) {
                $curlErrorString = curl_error($this->_ch);
                $this->_error($curlErrorString);

                $exception = new ConnectionErrorException('Unable to connect to "'.$this->uri.'": '
                        . $curlErrorNumber . ' ' . $curlErrorString);

                $exception->setCurlErrorNumber($curlErrorNumber)
                    ->setCurlErrorString($curlErrorString);

                throw $exception;
            }

            $this->_error('Unable to connect to "'.$this->uri.'".');
            throw new ConnectionErrorException('Unable to connect to "'.$this->uri.'".');
        }

        $info = curl_getinfo($this->_ch);

        // Remove the "HTTP/1.x 200 Connection established" string and any other headers added by proxy
        $proxy_regex = "/HTTP\/1\.[01] 200 Connection established.*?\r\n\r\n/si";
        if ($this->hasProxy() && preg_match($proxy_regex, $result)) {
            $result = preg_replace($proxy_regex, '', $result);
        }

        $response = explode("\r\n\r\n", $result, 2 + $info['redirect_count']);

        $body = array_pop($response);
        $headers = array_pop($response);

        return new Response($body, $headers, $this, $info);
    }