Skip to content

Commit

Permalink
fix: extend Exception for ResolutionError and provide non-overlapping…
Browse files Browse the repository at this point in the history
… methods
  • Loading branch information
tcarrio committed Nov 1, 2022
1 parent b1b6e25 commit 541ebc4
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 15 deletions.
4 changes: 2 additions & 2 deletions features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ public function theReasonShouldIndicateAnErrorAndTheErrorCodeShouldIndicateAMiss
$error = $details->getError();

Assert::assertNotNull($error);
Assert::assertEquals($errorCode, $error->getCode());
Assert::assertEquals($errorCode, $error->getResolutionErrorCode());
}

/**
Expand Down Expand Up @@ -392,7 +392,7 @@ public function theReasonShouldIndicateAnErrorAndTheErrorCodeShouldIndicateAType

Assert::assertNotNull($error);
Assert::assertEquals(
$error->getCode(),
$error->getResolutionErrorCode(),
ErrorCode::TYPE_MISMATCH(),
);
}
Expand Down
20 changes: 11 additions & 9 deletions src/implementation/provider/ResolutionError.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,29 @@

namespace OpenFeature\implementation\provider;

use Exception;
use OpenFeature\interfaces\provider\ErrorCode;
use OpenFeature\interfaces\provider\ResolutionError as ResolutionErrorInterface;

class ResolutionError implements ResolutionErrorInterface
class ResolutionError extends Exception implements ResolutionErrorInterface
{
private ErrorCode $code;
private ?string $message;
private ErrorCode $resolutionErrorCode;
private ?string $resolutionErrorMessage;

public function __construct(ErrorCode $code, ?string $message = null)
{
$this->code = $code;
$this->message = $message;
parent::__construct();
$this->resolutionErrorCode = $code;
$this->resolutionErrorMessage = $message;
}

public function getCode(): ErrorCode
public function getResolutionErrorCode(): ErrorCode
{
return $this->code;
return $this->resolutionErrorCode;
}

public function getMessage(): ?string
public function getResolutionErrorMessage(): ?string
{
return $this->message;
return $this->resolutionErrorMessage;
}
}
4 changes: 2 additions & 2 deletions src/interfaces/provider/ResolutionError.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ interface ResolutionError
* In cases of abnormal execution, the provider MUST indicate an error using the idioms of the implementation
* language, with an associated error code and optional associated error message.
*/
public function getCode(): ErrorCode;
public function getResolutionErrorCode(): ErrorCode;

/**
* ---------------
Expand All @@ -29,5 +29,5 @@ public function getCode(): ErrorCode;
* In cases of abnormal execution, the provider MUST indicate an error using the idioms of the implementation
* language, with an associated error code and optional associated error message.
*/
public function getMessage(): ?string;
public function getResolutionErrorMessage(): ?string;
}
2 changes: 1 addition & 1 deletion tests/unit/OpenFeatureClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ public function testClientEvaluationDetailsAbnormalExecutionHasErrorCodeField():
/** @var ResolutionError $resolutionError */
$resolutionError = $actualDetails->getError();
$this->assertNotNull($resolutionError);
$this->assertEquals($expectedErrorCode, $resolutionError->getCode());
$this->assertEquals($expectedErrorCode, $resolutionError->getResolutionErrorCode());
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/ProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ public function testMustPopulateErrorFieldInAbnormalExecution(): void
/** @var ResolutionError $resolutionError */
$resolutionError = $actualResolution->getError();
$this->assertNotNull($resolutionError);
$this->assertEquals($expectedErrorCode, $resolutionError->getCode());
$this->assertEquals($expectedErrorCode, $resolutionError->getResolutionErrorCode());
}

/**
Expand Down

0 comments on commit 541ebc4

Please sign in to comment.