Skip to content

Commit f73475b

Browse files
committed
Addressed comments
1 parent c9711bd commit f73475b

File tree

4 files changed

+20
-17
lines changed

4 files changed

+20
-17
lines changed

packages/firebase_data_connect/firebase_data_connect/lib/src/common/dataconnect_error.dart

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ part of 'common_library.dart';
1818
enum DataConnectErrorCode { unavailable, unauthorized, other }
1919

2020
/// Error thrown when DataConnect encounters an error.
21-
class DataConnectError<T> extends FirebaseException {
21+
class DataConnectError extends FirebaseException {
2222
DataConnectError(this.dataConnectErrorCode, String? message)
2323
: super(
2424
plugin: 'Data Connect',
@@ -29,11 +29,11 @@ class DataConnectError<T> extends FirebaseException {
2929
}
3030

3131
/// Error thrown when an operation is partially successful.
32-
class DataConnectOperationError extends DataConnectError {
32+
class DataConnectOperationError<T> extends DataConnectError {
3333
DataConnectOperationError(
3434
DataConnectErrorCode code, String message, this.response)
3535
: super(code, message);
36-
final DataConnectOperationFailureResponse response;
36+
final DataConnectOperationFailureResponse<T> response;
3737
}
3838

3939
/// Nested class containing errors and decoded data.
@@ -48,14 +48,20 @@ class DataConnectOperationFailureResponse<T> {
4848
class DataConnectOperationFailureResponseErrorInfo {
4949
DataConnectOperationFailureResponseErrorInfo(this.path, this.message);
5050
String message;
51-
List<DataConnectOperationFailureErrorInfoPathSegment> path;
51+
List<PathSegment> path;
5252
}
5353

5454
/// Path where error occurred.
55-
class DataConnectOperationFailureErrorInfoPathSegment {
56-
DataConnectOperationFailureErrorInfoPathSegment({this.field, this.listIndex});
57-
String? field;
58-
int? listIndex;
55+
sealed class PathSegment {}
56+
57+
class StringValue extends PathSegment {
58+
final String value;
59+
StringValue(this.value);
60+
}
61+
62+
class IntValue extends PathSegment {
63+
final int value;
64+
IntValue(this.value);
5965
}
6066

6167
typedef Serializer<Variables> = String Function(Variables vars);

packages/firebase_data_connect/firebase_data_connect/lib/src/network/grpc_transport.dart

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,8 @@ Data handleResponse<Data>(CommonResponse<Data> commonResponse) {
180180
.map((e) => DataConnectOperationFailureResponseErrorInfo(
181181
e.path.values
182182
.map((val) => val.hasStringValue()
183-
? DataConnectOperationFailureErrorInfoPathSegment(
184-
field: val.stringValue)
185-
: DataConnectOperationFailureErrorInfoPathSegment(
186-
listIndex: val.numberValue.toInt()))
183+
? StringValue(val.stringValue)
184+
: IntValue(val.numberValue.toInt()))
187185
.toList(),
188186
e.message))
189187
.toList();

packages/firebase_data_connect/firebase_data_connect/lib/src/network/rest_transport.dart

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,8 @@ class RestTransport implements DataConnectTransport {
150150
.map((e) => DataConnectOperationFailureResponseErrorInfo(
151151
(e['path'] as List)
152152
.map((val) => val.runtimeType == String
153-
? DataConnectOperationFailureErrorInfoPathSegment(
154-
field: val)
155-
: DataConnectOperationFailureErrorInfoPathSegment(
156-
listIndex: val))
153+
? StringValue(val)
154+
: IntValue(val))
157155
.toList(),
158156
e['message']))
159157
.toList();

packages/firebase_data_connect/firebase_data_connect/test/src/network/rest_transport_test.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,8 @@ void main() {
422422
e.response.data!['abc'] == 'def' &&
423423
e.response.errors.first.message ==
424424
'SQL query error: pq: duplicate key value violates unique constraint movie_pkey' &&
425-
e.response.errors.first.path[0].field == 'the_matrix' &&
425+
(e.response.errors.first.path[0] as StringValue).value ==
426+
'the_matrix' &&
426427
e.response.decodedData is AbcHolder &&
427428
(e.response.decodedData as AbcHolder).abc == 'def')),
428429
);

0 commit comments

Comments
 (0)