|
| 1 | +/// Base exception class for all policy SDK related errors. |
| 2 | +/// |
| 3 | +/// This abstract class provides a common interface for all exceptions |
| 4 | +/// thrown by the policy engine, ensuring consistent error handling |
| 5 | +/// and messaging across the SDK. |
| 6 | +abstract class IPolicySDKException implements Exception { |
| 7 | + /// Creates a new PolicySDKException with the given error message. |
| 8 | + /// |
| 9 | + /// [message] should provide a clear description of what went wrong. |
| 10 | + const IPolicySDKException(this.message); |
| 11 | + |
| 12 | + /// The error message describing the exception. |
| 13 | + final String message; |
| 14 | + |
| 15 | + @override |
| 16 | + String toString() => 'PolicySDKException: $message'; |
| 17 | +} |
| 18 | + |
| 19 | +/// Abstract exception for detailed policy SDK errors with contextual information. |
| 20 | +/// |
| 21 | +/// This class extends [IPolicySDKException] to provide additional context for |
| 22 | +/// errors that occur within the policy engine, such as the specific key involved, |
| 23 | +/// the original error thrown, and a map of field-specific validation errors. |
| 24 | +/// Subclasses should use this to represent exceptions where more granular |
| 25 | +/// diagnostic information is valuable for debugging or reporting. |
| 26 | +abstract class IDetailPolicySDKException implements IPolicySDKException { |
| 27 | + /// Creates a new [IDetailPolicySDKException] with an error [message] and optional details. |
| 28 | + /// |
| 29 | + /// [message] provides a human-readable description of the error. |
| 30 | + /// [key] optionally identifies the specific key or field related to the error. |
| 31 | + /// [originalError] optionally contains the original error object that triggered this exception. |
| 32 | + /// [errors] optionally provides a map of field-specific validation errors. |
| 33 | + const IDetailPolicySDKException( |
| 34 | + this.message, { |
| 35 | + this.key, |
| 36 | + this.originalError, |
| 37 | + this.errors, |
| 38 | + }); |
| 39 | + |
| 40 | + @override |
| 41 | + final String message; |
| 42 | + |
| 43 | + /// The specific key or field that caused the error, if applicable. |
| 44 | + final String? key; |
| 45 | + |
| 46 | + /// The original error object that led to this exception, if available. |
| 47 | + final Object? originalError; |
| 48 | + |
| 49 | + /// A map of field-specific validation errors encountered during processing, if any. |
| 50 | + final Map<String, String>? errors; |
| 51 | +} |
0 commit comments