Skip to content

Commit

Permalink
Merge pull request #352 from mesilov/330-add-crm-item-support
Browse files Browse the repository at this point in the history
fix errors for Core
  • Loading branch information
mesilov authored Sep 8, 2023
2 parents d1c057f + eb1f34a commit 8ec5051
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@
* fix [add helper metods isError for registerCallResult fortelephony](https://github.com/mesilov/bitrix24-php-sdk/issues/335)
* fix [add return type for crm multifields phone, email, im](https://github.com/mesilov/bitrix24-php-sdk/issues/338)
* fix errors in `ShowFieldsDescriptionCommand` metadata reader CLI command
* fix errors for `ApplicationProfile` with empty scope
* fix errors for `ApplicationProfile` with empty scope
* fix errors in `Core` with auth attempt to non-exists portal

### etc
* move CLI entry point to `bin/console`
Expand Down
10 changes: 10 additions & 0 deletions src/Core/Core.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Bitrix24\SDK\Core\Commands\Command;
use Bitrix24\SDK\Core\Contracts\ApiClientInterface;
use Bitrix24\SDK\Core\Contracts\CoreInterface;
use Bitrix24\SDK\Core\Exceptions\AuthForbiddenException;
use Bitrix24\SDK\Core\Exceptions\BaseException;
use Bitrix24\SDK\Core\Exceptions\TransportException;
use Bitrix24\SDK\Core\Response\Response;
Expand Down Expand Up @@ -146,6 +147,15 @@ public function call(string $apiMethod, array $parameters = []): Response
throw new BaseException('UNAUTHORIZED request error');
}
break;
case StatusCodeInterface::STATUS_FORBIDDEN:
$this->logger->warning(
'bitrix24 portal authorisation forbidden',
[
'apiMethod' => $apiMethod,
'b24DomainUrl' => $this->apiClient->getCredentials()->getDomainUrl(),
]
);
throw new AuthForbiddenException(sprintf('authorisation forbidden for portal %s ', $this->apiClient->getCredentials()->getDomainUrl()));
case StatusCodeInterface::STATUS_SERVICE_UNAVAILABLE:
$body = $apiCallResponse->toArray(false);
$this->logger->notice(
Expand Down
9 changes: 9 additions & 0 deletions src/Core/Exceptions/AuthForbiddenException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

declare(strict_types=1);

namespace Bitrix24\SDK\Core\Exceptions;

class AuthForbiddenException extends BaseException
{
}
19 changes: 19 additions & 0 deletions tests/Integration/Core/CoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
namespace Bitrix24\SDK\Tests\Integration\Core;

use Bitrix24\SDK\Core\Contracts\CoreInterface;
use Bitrix24\SDK\Core\CoreBuilder;
use Bitrix24\SDK\Core\Credentials\AccessToken;
use Bitrix24\SDK\Core\Credentials\ApplicationProfile;
use Bitrix24\SDK\Core\Credentials\Credentials;
use Bitrix24\SDK\Core\Credentials\Scope;
use Bitrix24\SDK\Core\Exceptions\AuthForbiddenException;
use Bitrix24\SDK\Core\Exceptions\MethodNotFoundException;
use Bitrix24\SDK\Tests\Integration\Fabric;
use PHPUnit\Framework\TestCase;
Expand All @@ -28,6 +34,19 @@ public function testCallExistingApiMethod(): void
$this->assertIsArray($response->getResponseData()->getResult());
}

public function testConnectToNonExistsBitrix24PortalInCloud():void
{
$core = (new CoreBuilder())
->withCredentials(Credentials::createFromOAuth(
new AccessToken('non-exists-access-token','refresh-token', 3600),
new ApplicationProfile('non-exists-client-id', 'non-exists-client-secret', new Scope([])),
'non-exists-domain.bitrix24.com'
))
->build();
$this->expectException(AuthForbiddenException::class);
$core->call('app.info');
}

/**
* @return void
* @throws \Bitrix24\SDK\Core\Exceptions\BaseException
Expand Down

0 comments on commit 8ec5051

Please sign in to comment.