Skip to content

Commit cbc5472

Browse files
refactor(exceptions): streamline exception constructors and enhance documentation
1 parent f1c131d commit cbc5472

File tree

4 files changed

+53
-29
lines changed

4 files changed

+53
-29
lines changed

lib/src/exceptions/json_parse_exception.dart

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,19 @@ import 'package:flutter_policy_engine/src/exceptions/i_policy_sdk_exceptions.dar
88
/// the specific key that failed, the original error, and any additional
99
/// validation errors.
1010
class JsonParseException implements IDetailPolicySDKException {
11+
/// Creates a new JsonParseException.
12+
///
13+
/// [message] should describe the parsing failure.
14+
/// [key] optionally specifies which JSON key caused the failure.
15+
/// [originalError] optionally provides the original parsing error.
16+
/// [errors] optionally provides a map of field-specific validation errors.
17+
JsonParseException(
18+
this.message, {
19+
this.key,
20+
this.originalError,
21+
this.errors,
22+
});
23+
1124
@override
1225
final String message;
1326

@@ -23,19 +36,6 @@ class JsonParseException implements IDetailPolicySDKException {
2336
@override
2437
final Map<String, String>? errors;
2538

26-
/// Creates a new JsonParseException.
27-
///
28-
/// [message] should describe the parsing failure.
29-
/// [key] optionally specifies which JSON key caused the failure.
30-
/// [originalError] optionally provides the original parsing error.
31-
/// [errors] optionally provides a map of field-specific validation errors.
32-
JsonParseException(
33-
this.message, {
34-
this.key,
35-
this.originalError,
36-
this.errors,
37-
});
38-
3939
@override
4040
String toString() {
4141
final buffer = StringBuffer('JsonParseException: $message');

lib/src/exceptions/json_serialize_exception.dart

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,19 @@ import 'package:flutter_policy_engine/src/exceptions/i_policy_sdk_exceptions.dar
77
/// occurs when policy objects contain non-serializable data types
88
/// or circular references.
99
class JsonSerializeException implements IDetailPolicySDKException {
10+
/// Creates a new JsonSerializeException.
11+
///
12+
/// [message] should describe the serialization failure.
13+
/// [key] optionally specifies which object key caused the failure.
14+
/// [originalError] optionally provides the original serialization error.
15+
/// [errors] optionally provides a map of field-specific serialization errors.
16+
JsonSerializeException(
17+
this.message, {
18+
this.key,
19+
this.originalError,
20+
this.errors,
21+
});
22+
1023
@override
1124
final String message;
1225

@@ -22,19 +35,6 @@ class JsonSerializeException implements IDetailPolicySDKException {
2235
@override
2336
final Map<String, String>? errors;
2437

25-
/// Creates a new JsonSerializeException.
26-
///
27-
/// [message] should describe the serialization failure.
28-
/// [key] optionally specifies which object key caused the failure.
29-
/// [originalError] optionally provides the original serialization error.
30-
/// [errors] optionally provides a map of field-specific serialization errors.
31-
JsonSerializeException(
32-
this.message, {
33-
this.key,
34-
this.originalError,
35-
this.errors,
36-
});
37-
3838
@override
3939
String toString() {
4040
final buffer = StringBuffer('JsonSerializeException: $message');

lib/src/exceptions/policy_not_initialized_exception.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@ import 'package:flutter_policy_engine/src/exceptions/i_policy_sdk_exceptions.dar
1515
/// }
1616
/// ```
1717
class PolicyNotInitializedException implements IPolicySDKException {
18+
/// Creates a new [PolicyNotInitializedException] with the given [message].
19+
const PolicyNotInitializedException(
20+
this.message,
21+
);
22+
1823
/// A message describing the initialization error.
1924
@override
2025
final String message;
2126

22-
/// Creates a new [PolicyNotInitializedException] with the given [message].
23-
const PolicyNotInitializedException(this.message);
24-
2527
@override
2628
String toString() {
2729
final buffer = StringBuffer('PolicyNotInitializedException: $message');
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import 'package:flutter_policy_engine/src/exceptions/i_policy_sdk_exceptions.dart';
2+
3+
class PolicySDKException implements IPolicySDKException {
4+
PolicySDKException(
5+
this.message, {
6+
required this.exception,
7+
});
8+
9+
@override
10+
final String message;
11+
12+
final Exception? exception;
13+
14+
@override
15+
String toString() {
16+
final buffer = StringBuffer('SDKException: $message');
17+
if (exception != null) {
18+
buffer.write('\nExtra info: ${exception?.toString()}');
19+
}
20+
return buffer.toString();
21+
}
22+
}

0 commit comments

Comments
 (0)