Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(api): Decode optional ErrorType property #2852

Merged
merged 3 commits into from
Apr 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class GraphQLResponseError {
this.locations,
this.path,
this.extensions,
this.errorType,
this.errorInfo,
});

factory GraphQLResponseError.fromJson(Map<String, dynamic> json) {
Expand All @@ -34,6 +36,8 @@ class GraphQLResponseError {
.toList(),
path: json['path'] as List?,
extensions: (json['extensions'] as Map?)?.cast<String, dynamic>(),
errorType: json['errorType'] as String?,
errorInfo: (json['errorInfo'] as Map?)?.cast<String, dynamic>(),
);
}

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

/// The type of error.
final String? errorType;

/// Additional info.
final Map<String, dynamic>? errorInfo;

Map<String, dynamic> toJson() => <String, dynamic>{
'message': message,
if (locations != null)
'locations': locations?.map((e) => e.toJson()).toList(),
if (path != null) 'path': path,
if (extensions != null) 'extensions': extensions,
if (errorType != null) 'errorType': errorType,
if (errorInfo != null) 'errorInfo': errorInfo,
};

@override
bool operator ==(Object other) =>
identical(this, other) ||
other is GraphQLResponseError &&
const DeepCollectionEquality().equals(
[message, locations, path, extensions],
[message, locations, path, extensions, errorType, errorInfo],
[
other.message,
other.locations,
other.path,
other.extensions,
other.errorType,
other.errorInfo,
],
);

Expand All @@ -77,6 +91,8 @@ class GraphQLResponseError {
locations,
path,
extensions,
errorType,
errorInfo,
]);

@override
Expand Down
6 changes: 6 additions & 0 deletions packages/api/amplify_api_dart/test/graphql_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ const _errorExtensions = {
'a': 'blah',
'b': {'c': 'd'}
};
const _errorType = 'DynamoDB:ConditionalCheckFailedException';
const _errorInfo = {'a': 'b'};
const _expectedErrorResponseBody = {
'data': null,
'errors': [
Expand All @@ -74,6 +76,8 @@ const _expectedErrorResponseBody = {
'locations': _errorLocations,
'path': _errorPath,
'extensions': _errorExtensions,
'errorType': _errorType,
'errorInfo': _errorInfo,
},
]
};
Expand Down Expand Up @@ -553,6 +557,8 @@ void main() {
],
path: <dynamic>[..._errorPath],
extensions: <String, dynamic>{..._errorExtensions},
errorType: _errorType,
errorInfo: _errorInfo,
);

expect(res.data, equals(null));
Expand Down