Skip to content

Commit 9aa9dca

Browse files
authored
chore(api): Decode optional ErrorType property (#2852)
* chore(api): Decode optional ErrorType property * chore: added errorInfo property
1 parent 1efbc10 commit 9aa9dca

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

packages/amplify_core/lib/src/types/api/graphql/graphql_response_error.dart

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ class GraphQLResponseError {
1919
this.locations,
2020
this.path,
2121
this.extensions,
22+
this.errorType,
23+
this.errorInfo,
2224
});
2325

2426
factory GraphQLResponseError.fromJson(Map<String, dynamic> json) {
@@ -34,6 +36,8 @@ class GraphQLResponseError {
3436
.toList(),
3537
path: json['path'] as List?,
3638
extensions: (json['extensions'] as Map?)?.cast<String, dynamic>(),
39+
errorType: json['errorType'] as String?,
40+
errorInfo: (json['errorInfo'] as Map?)?.cast<String, dynamic>(),
3741
);
3842
}
3943

@@ -49,25 +53,35 @@ class GraphQLResponseError {
4953
/// Additional context.
5054
final Map<String, dynamic>? extensions;
5155

56+
/// The type of error.
57+
final String? errorType;
58+
59+
/// Additional info.
60+
final Map<String, dynamic>? errorInfo;
61+
5262
Map<String, dynamic> toJson() => <String, dynamic>{
5363
'message': message,
5464
if (locations != null)
5565
'locations': locations?.map((e) => e.toJson()).toList(),
5666
if (path != null) 'path': path,
5767
if (extensions != null) 'extensions': extensions,
68+
if (errorType != null) 'errorType': errorType,
69+
if (errorInfo != null) 'errorInfo': errorInfo,
5870
};
5971

6072
@override
6173
bool operator ==(Object other) =>
6274
identical(this, other) ||
6375
other is GraphQLResponseError &&
6476
const DeepCollectionEquality().equals(
65-
[message, locations, path, extensions],
77+
[message, locations, path, extensions, errorType, errorInfo],
6678
[
6779
other.message,
6880
other.locations,
6981
other.path,
7082
other.extensions,
83+
other.errorType,
84+
other.errorInfo,
7185
],
7286
);
7387

@@ -77,6 +91,8 @@ class GraphQLResponseError {
7791
locations,
7892
path,
7993
extensions,
94+
errorType,
95+
errorInfo,
8096
]);
8197

8298
@override

packages/api/amplify_api_dart/test/graphql_test.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ const _errorExtensions = {
6666
'a': 'blah',
6767
'b': {'c': 'd'}
6868
};
69+
const _errorType = 'DynamoDB:ConditionalCheckFailedException';
70+
const _errorInfo = {'a': 'b'};
6971
const _expectedErrorResponseBody = {
7072
'data': null,
7173
'errors': [
@@ -74,6 +76,8 @@ const _expectedErrorResponseBody = {
7476
'locations': _errorLocations,
7577
'path': _errorPath,
7678
'extensions': _errorExtensions,
79+
'errorType': _errorType,
80+
'errorInfo': _errorInfo,
7781
},
7882
]
7983
};
@@ -553,6 +557,8 @@ void main() {
553557
],
554558
path: <dynamic>[..._errorPath],
555559
extensions: <String, dynamic>{..._errorExtensions},
560+
errorType: _errorType,
561+
errorInfo: _errorInfo,
556562
);
557563

558564
expect(res.data, equals(null));

0 commit comments

Comments
 (0)