deciphers data returned from Habbo and tries to throw the correct exception

@param $data
@throws Exception
@throws HabboNotFoundException
@throws MaintenanceException
@throws UserInvalidException
548096
public static function throwHabboAPIException($data)
    {
        // Do we find 'maintenance' anywhere?
        if (strstr($data, 'maintenance')) {
            throw new MaintenanceException("Hotel API is down for maintenance");
        }

        // Check if data is JSON
        if ($data[0] == "{") { // Quick 'hack' to see if this could be JSON
            $json = json_decode($data, true);
            if (isset($json['errors'])) {
                if ($json['errors'][0]['msg'] == "user.invalid_name") {
                    throw new UserInvalidException("The name you supplied appears to be invalid");
                }
                $defaultMessage = $json['errors'][0]['msg'];
            } else if (isset($json['error'])) {
                if (preg_match('#not-found#', $json['error'])) {
                    throw new HabboNotFoundException("We can not find the Habbo you're looking for");
                }
                $defaultMessage = $json['error'];
            } else {
                $defaultMessage = $json;
            }
        } else {
            $defaultMessage = "An unknown HTML page was returned";
        }

        throw new Exception("Unknown HabboAPI exception occurred: " . $defaultMessage);
    }
1038122
public function unserialize($data)
    {
        if (!is_string($data)) {
            throw new \common_exception_InconsistentData('The encoded resource metadata should be provided as a string');
        }

        $metaData = json_decode($data, true);

        if (!is_array($metaData)) {
            throw new \common_exception_InconsistentData('The decoded resource metadata should be an array');
        }
        $this->metaData = $metaData;

        return $this->metaData;
    }
183030
protected function checkData(array $data)
    {
        if (! isset($data[self::STATUS]) || ! in_array($data[self::STATUS], self::$availableStatus)) {
            throw new \common_Exception(
                __('A maintenance status must have a STATUS: "%s" or "%s"', self::LIVE_MODE, self::OFFLINE_MODE)
            );
        }
    }
978757
public function decrypt(string $data)
    {
        $this->throwExceptionIfKeyEmpty();

        if ($data === '') {
            return '';
        }

        list($encrypted_data, $iv) = \explode('::', \base64_decode($data, true), 2);

        return \openssl_decrypt($encrypted_data, $this->method, $this->key, 0, $iv);
    }
340047
protected function _throwException($exception = null)
    {
        if ($exception !== null) {
            if (!Configure::read('debug') && $exception instanceof SecurityException) {
                $exception->setReason($exception->getMessage());
                $exception->setMessage(self::DEFAULT_EXCEPTION_MESSAGE);
            }
            throw $exception;
        }
        throw new BadRequestException(self::DEFAULT_EXCEPTION_MESSAGE);
    }
468428
protected function HLUpdate(array $data)
    {
        $return = [];
        if (empty($data['NAME'])) {
            throw new Exception('You must set NAME');
        }
        if ($id = $this->HLGetIdByCode($data['NAME'])) {
            $arLoad = $data;
            unset($arLoad['LANGS'], $arLoad['RIGHTS'], $arLoad['NAME']);
            if ($arLoad) {
                $result = HighloadBlockTable::update($id, $arLoad);
                if ($result->isSuccess()) {
                    if (!empty($data['LANGS'])) {
                        $this->HLSetLangs($id, $data['LANGS']);
                    }
                    if (!empty($data['RIGHTS'])) {
                        $this->HLSetRights($id, $data['RIGHTS']);
                    }
                    $return[] = "Update {$data['NAME']} ({$id}) highload block";
                } else {
                    throw new Exception("Can't update {$data['NAME']} ({$id}) highload block: " . implode(', ', $result->getErrorMessages()));
                }
            } elseif (!empty($data['RIGHTS'])) {
                $this->HLSetRights($id, $data['RIGHTS']);
            } elseif (!empty($data['LANGS'])) {
                $this->HLSetLangs($id, $data['LANGS']);
            }
        } else {
            throw new Exception("Hl entity with name {$data['NAME']} does not exist");
        }

        return $return;
    }
1161409
public function decode($data)
    {
        if (is_string($data)) {
            $this->arrayData = json_decode($data, true); // true gives us associative arrays
        }

        if (!is_string($data) || !$this->isValidJson()) {
            throw new JsonDecodingFailedException('The data provided was not proper JSON');
        }

        return $this->arrayData;
    }
1233917
public function put($data)
	{
		if( ! $data instanceof DataTransferObject)
		{
			throw new Exception('You are trying to put invalid object to trunk.');
		}

		if( ! array_key_exists($data->getType(), $this->storage) )
		{
			$this->storage[$data->getType()] = [];
		}

		$storageKey = $this->storageKey($data->getParams());
		$this->storage[$data->getType()][$storageKey] = $data;
	}
491736
public function encrypt($data)
    {
        /** @var string $binary */
        $binary = $this->config('binary');

        if ($binary) {
            $this->_binary = $binary;
        }

        if (!is_executable($this->_binary)) {
            throw new Exception(sprintf('pdftk binary is not found or not executable: %s', $this->_binary));
        }

        $arguments = [];

        $ownerPassword = $this->_Pdf->ownerPassword();
        if ($ownerPassword !== null) {
            $arguments['owner_pw'] = escapeshellarg($ownerPassword);
        }

        $userPassword = $this->_Pdf->userPassword();
        if ($userPassword !== null) {
            $arguments['user_pw'] = escapeshellarg($userPassword);
        }

        $allowed = $this->_buildPermissionsArgument();
        if ($allowed) {
            $arguments['allow'] = $allowed;
        }

        if (!$ownerPassword && !$userPassword) {
            throw new Exception('Crypto: Required to configure atleast an ownerPassword or userPassword');
        }

        if ($ownerPassword == $userPassword) {
            throw new Exception('Crypto: ownerPassword and userPassword cannot be the same');
        }

        $command = sprintf('%s - output - %s', $this->_binary, $this->_buildArguments($arguments));

        $descriptorspec = [
            0 => ['pipe', 'r'], // feed stdin of process from this file descriptor
            1 => ['pipe', 'w'], // Note you can also grab stdout from a pipe, no need for temp file
            2 => ['pipe', 'w'], // stderr
        ];

        $prochandle = proc_open($command, $descriptorspec, $pipes);

        fwrite($pipes[0], $data);
        fclose($pipes[0]);

        $stdout = stream_get_contents($pipes[1]);
        fclose($pipes[1]);
        $stderr = stream_get_contents($pipes[2]);
        fclose($pipes[2]);

        $exitcode = proc_close($prochandle);

        if ($exitcode !== 0) {
            throw new Exception(sprintf('Crypto: Unknown error (exit code %d)', $exitcode));
        }

        return $stdout;
    }
385355
protected function throwError($exception)
    {
        switch ($exception->getResponse()->getStatusCode()) {
            case 400:
                throw new BadRequestException($exception);
                break;

            case 401:
                throw new UnauthorizedException($exception);
                break;

            case 403:
                throw new MethodNotAllowedException($exception);
                break;

            case 404:
                throw new NotFoundException($exception);
                break;

            default:
                throw new Exception($exception);
                break;
        }
    }
108072
protected function checkReadonlyField(&$data) {
        if(!empty($this->readonlyField)) {
            foreach ($this->readonlyField as $key=>$field){
                if(isset($data[$field]))
                    unset($data[$field]);
            }
        }
        return $data;
    }
963989
public function decode(string $data)
    {
        try {
            return eval('return ' . $data . ';');
        } catch (\ParseError $e) {
            throw new DecodeException($e->getMessage(), $e->getCode(), $e);
        }

    }
991682
public function check($data)
    {
        foreach ($this->requiredFields as $field => $type)
        {
            if (! isset($data[$field]) || empty($data[$field]) || ! $this->isValid($data[$field], $type)) {

                throw new ValidatorException(ValidatorException::INVALID_INTEGRITY, $this->debugDump($field, $data));
            }
        }

        foreach ($this->optionalFields as $field => $expectedType)
        {
            if (! isset($data[$field])) {
                continue;
            }

            if (! $this->isValid($data[$field], $expectedType)) {
                throw new ValidatorException(ValidatorException::INVALID_INTEGRITY, $this->debugDump($field, $data));
            }
        }

        return true;
    }
1035588
private function parse_result($data) {
    try {
      if ($this->resp_type == 'json') {
        $result = @json_decode($data);
      } else {
        $result = @simplexml_load_string($data);
      }
    } catch (Exception $e) {
      throw new GiantBombException('Parse error occoured', null, $e);
    }

    if (empty($result)) {
      throw new GiantBombException('Unknown error occured');
    } else if (!empty($result->error) && strtoupper($result->error) != 'OK') {
      throw new GiantBombException('Following error encountered: ' . $result->error);
    }

    return $result;
  }
262004
public function exception($msg, $data = null)
    {
        $this->last_selector = null;

        return $this->cmd(7, array(
            $msg,
            $data
        ));
    }
779947
public function unserialize($data)
    {
        $data = @unserialize($data);
        if (!is_array($data) ||
            !isset($data[0]) ||
            ($data[0] != self::VERSION)) {
            throw new Horde_Mime_Exception('Cache version change');
        }

        $this->_headers = new Horde_Support_CaseInsensitiveArray($data[1]);
        // TODO: BC
        $this->_eol = $data[2];
    }
917841
public function authenticationFailed($data)
    {
        // LDAP authentication uses a "Login" POST field instead of Email.
        $login = isset($data['Login'])
            ? $data['Login']
            : (isset($data[Email::class]) ? $data[Email::class] : '');

        if (empty($login)) {
            return $this->getAuditLogger()->warning(
                'Could not determine username/email of failed authentication. '.
                'This could be due to login form not using Email or Login field for POST data.'
            );
        }

        $this->getAuditLogger()->info(sprintf('Failed login attempt using email "%s"', $login));
    }