Skip to content

Commit 58e97d2

Browse files
authored
fix: Improve error handling in OpenFeatureClient (#121)
## This PR The PR adds the `flagKey` to EvaluationDetailsBuilder during error handling, providing more context for debugging. It also includes error message within the ResolutionError for more complete error information. ### How to test Modify the NoOpProvider to throw any exception with a message. This should then propergate through to this new error handling Signed-off-by: Andrew Menino-Barlow <[email protected]>
1 parent 2123274 commit 58e97d2

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

Diff for: src/OpenFeatureClient.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -372,9 +372,10 @@ private function evaluateFlag(
372372
),
373373
);
374374

375-
$error = $err instanceof ThrowableWithResolutionError ? $err->getResolutionError() : new ResolutionError(ErrorCode::GENERAL());
375+
$error = $err instanceof ThrowableWithResolutionError ? $err->getResolutionError() : new ResolutionError(ErrorCode::GENERAL(), $err->getMessage());
376376

377377
$details = (new EvaluationDetailsBuilder())
378+
->withFlagKey($flagKey)
378379
->withValue($defaultValue)
379380
->withReason(Reason::ERROR)
380381
->withError($error)

Diff for: tests/unit/OpenFeatureClientTest.php

+8-2
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,7 @@ public function testClientEvaluationDetailsAbnormalExecutionHasErrorCodeField():
499499
$resolutionError = $actualDetails->getError();
500500
$this->assertNotNull($resolutionError);
501501
$this->assertEquals($expectedErrorCode, $resolutionError->getResolutionErrorCode());
502+
$this->assertEquals('flagKey', $actualDetails->getFlagKey());
502503
}
503504

504505
/**
@@ -563,9 +564,14 @@ public function testClientShouldLogInformativeErrorDuringAbnormalExecution(): vo
563564
$client = new OpenFeatureClient($api, 'test-name', 'test-version');
564565
$client->setLogger($mockLogger);
565566

566-
$value = $client->getBooleanValue('flagKey', false);
567+
$details = $client->getBooleanDetails('flagKey', false);
567568

568-
$this->assertEquals($value, false);
569+
$this->assertEquals(false, $details->getValue());
570+
$this->assertEquals('flagKey', $details->getFlagKey());
571+
572+
$this->assertInstanceOf(ResolutionError::class, $details->getError());
573+
$this->assertEquals(ErrorCode::GENERAL(), $details->getError()->getResolutionErrorCode());
574+
$this->assertEquals('NETWORK_ERROR', $details->getError()->getResolutionErrorMessage());
569575
}
570576

571577
/**

0 commit comments

Comments
 (0)