Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce ApiComponent as proxy for BEditaClient #21

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

batopa
Copy link
Member

@batopa batopa commented May 28, 2020

This PR is a proposal to try to make more easy to handle errors thrown by BEditaClient.

The Component is a proxy to BEditaClient and should be setup in Controller::initialize() method

$this->loadComponent('BEdita/WebTools.Api', [
    'apiClient' => ApiClientProvider::getApiClient(),
    'exceptionsEnabled` => true // default to true
]);

In this way the component throws exceptions as BEditaClient usually do.

In the Controller action we can use the component transparently as if we were using a BEditaClient instance

$response = $this->Api->getObject('gustavo'); // if gustavo not exists a BEditaClientException will be thrown

If we don't want to throw exception but handle the error we can do

$response = $this->Api
    ->enableExceptions(false)
    ->getObject('gustavo');

if ($this->Api->hasError()) {
    $this->Flash->error($this->Api->getError());
}

When the exceptions are disabled the last error is stored in ApiComponent and reset at every request delegated to BEditaClient

@codecov-commenter
Copy link

codecov-commenter commented May 28, 2020

Codecov Report

Merging #21 into master will increase coverage by 0.91%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master      #21      +/-   ##
============================================
+ Coverage     85.53%   86.45%   +0.91%     
- Complexity      132      141       +9     
============================================
  Files            16       17       +1     
  Lines           325      347      +22     
============================================
+ Hits            278      300      +22     
  Misses           47       47              
Impacted Files Coverage Δ Complexity Δ
src/Controller/Component/ApiComponent.php 100.00% <100.00%> (ø) 9.00 <9.00> (?)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cc6c53d...5fd8c94. Read the comment docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants