Skip to content

Commit

Permalink
Remove unnecessary exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
stfndamjanovic committed Jan 25, 2024
1 parent 9656690 commit 34705ec
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 38 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ The `Open` state indicates that the circuit breaker has detected a critical fail

### Force Open

`Force Open` is not part of the regular flow. It can be utilized when intentional suspension of calls to a service is required. In this state, a `CircuitForceOpenException` will be thrown.
`Force Open` is not part of the regular flow. It can be utilized when intentional suspension of calls to a service is required. In this state, a `CircuitOpenException` will be thrown.

To force the circuit breaker into the Force Open state, use the following:
```php
Expand Down
11 changes: 0 additions & 11 deletions src/Exceptions/CircuitForceOpenException.php

This file was deleted.

14 changes: 0 additions & 14 deletions src/Exceptions/CircuitHalfOpenFailException.php

This file was deleted.

6 changes: 3 additions & 3 deletions src/StateHandlers/ForceOpenStateHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

namespace Stfn\CircuitBreaker\StateHandlers;

use Stfn\CircuitBreaker\Exceptions\CircuitForceOpenException;
use Stfn\CircuitBreaker\Exceptions\CircuitOpenException;

class ForceOpenStateHandler extends StateHandler
{
/**
* @param \Closure $action
* @param ...$args
* @return void
* @throws CircuitForceOpenException
* @throws CircuitOpenException
*/
public function beforeCall(\Closure $action, ...$args)
{
throw CircuitForceOpenException::make();
throw CircuitOpenException::make($this->breaker->getName());
}
}
5 changes: 0 additions & 5 deletions src/StateHandlers/HalfOpenStateHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Stfn\CircuitBreaker\StateHandlers;

use Stfn\CircuitBreaker\Exceptions\CircuitHalfOpenFailException;

class HalfOpenStateHandler extends StateHandler
{
/**
Expand All @@ -23,12 +21,9 @@ public function onSucess()
/**
* @param \Exception $exception
* @return void
* @throws CircuitHalfOpenFailException
*/
public function onFailure(\Exception $exception)
{
$this->breaker->openCircuit();

throw CircuitHalfOpenFailException::make();
}
}
6 changes: 2 additions & 4 deletions tests/CircuitBreakerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
use Stfn\CircuitBreaker\CircuitBreaker;
use Stfn\CircuitBreaker\CircuitBreakerListener;
use Stfn\CircuitBreaker\CircuitState;
use Stfn\CircuitBreaker\Exceptions\CircuitForceOpenException;
use Stfn\CircuitBreaker\Exceptions\CircuitHalfOpenFailException;
use Stfn\CircuitBreaker\Exceptions\CircuitOpenException;
use Stfn\CircuitBreaker\Storage\InMemoryStorage;
use Stfn\CircuitBreaker\Storage\RedisStorage;
Expand Down Expand Up @@ -125,7 +123,7 @@ public function test_if_it_will_transit_back_to_open_state_after_first_fail()
throw new \Exception();
};

$this->expectException(CircuitHalfOpenFailException::class);
$this->expectException(\Exception::class);

$breaker->call($fail);

Expand Down Expand Up @@ -248,7 +246,7 @@ public function test_if_it_can_force_open_circuit()
$breaker = CircuitBreaker::for('test-service');
$breaker->forceOpenCircuit();

$this->expectException(CircuitForceOpenException::class);
$this->expectException(CircuitOpenException::class);

$breaker->call(fn () => true);
}
Expand Down

0 comments on commit 34705ec

Please sign in to comment.