-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: run error hook when provider returns reason error or error code (#…
…926) ## This PR - runs error hook when provider returns reason error or error code ### Related Issues Fixes #925 ### Notes Based on a conversation in Slack: https://cloud-native.slack.com/archives/C06E4DE6S07/p1714581197391509 --------- Signed-off-by: Michael Beemer <beeme1mr@users.noreply.github.com>
- Loading branch information
Showing
6 changed files
with
120 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,45 @@ | ||
export * from './general-error'; | ||
export * from './flag-not-found-error'; | ||
export * from './parse-error'; | ||
export * from './type-mismatch-error'; | ||
export * from './targeting-key-missing-error'; | ||
export * from './invalid-context-error'; | ||
export * from './open-feature-error-abstract'; | ||
export * from './provider-not-ready-error'; | ||
export * from './provider-fatal-error'; | ||
import { ErrorCode } from '../evaluation'; | ||
|
||
import { FlagNotFoundError } from './flag-not-found-error'; | ||
import { GeneralError } from './general-error'; | ||
import { InvalidContextError } from './invalid-context-error'; | ||
import { OpenFeatureError } from './open-feature-error-abstract'; | ||
import { ParseError } from './parse-error'; | ||
import { ProviderFatalError } from './provider-fatal-error'; | ||
import { ProviderNotReadyError } from './provider-not-ready-error'; | ||
import { TargetingKeyMissingError } from './targeting-key-missing-error'; | ||
import { TypeMismatchError } from './type-mismatch-error'; | ||
|
||
const instantiateErrorByErrorCode = (errorCode: ErrorCode, message?: string): OpenFeatureError => { | ||
switch (errorCode) { | ||
case ErrorCode.FLAG_NOT_FOUND: | ||
return new FlagNotFoundError(message); | ||
case ErrorCode.PARSE_ERROR: | ||
return new ParseError(message); | ||
case ErrorCode.TYPE_MISMATCH: | ||
return new TypeMismatchError(message); | ||
case ErrorCode.TARGETING_KEY_MISSING: | ||
return new TargetingKeyMissingError(message); | ||
case ErrorCode.INVALID_CONTEXT: | ||
return new InvalidContextError(message); | ||
case ErrorCode.PROVIDER_NOT_READY: | ||
return new ProviderNotReadyError(message); | ||
case ErrorCode.PROVIDER_FATAL: | ||
return new ProviderFatalError(message); | ||
default: | ||
return new GeneralError(message); | ||
} | ||
}; | ||
|
||
export { | ||
FlagNotFoundError, | ||
GeneralError, | ||
InvalidContextError, | ||
ParseError, | ||
ProviderFatalError, | ||
ProviderNotReadyError, | ||
TargetingKeyMissingError, | ||
TypeMismatchError, | ||
OpenFeatureError, | ||
instantiateErrorByErrorCode, | ||
}; |