You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by "alexeyinkin (via GitHub)" <gi...@apache.org> on 2023/02/10 11:04:36 UTC

[GitHub] [beam] alexeyinkin commented on a diff in pull request #25397: Issue25329 fix cors issue when no internet

alexeyinkin commented on code in PR #25397:
URL: https://github.com/apache/beam/pull/25397#discussion_r1102607882


##########
playground/frontend/playground_components/lib/src/controllers/playground_controller.dart:
##########
@@ -49,6 +49,7 @@ const kTitle = 'Catalog';
 const kExecutionCancelledText = '\nPipeline cancelled';
 const kPipelineOptionsParseError =
     'Failed to parse pipeline options, please check the format (example: --key1 value1 --key2 value2), only alphanumeric and ",*,/,-,:,;,\',. symbols are allowed';
+const kInternetConnectionUnavailable = 'Internet connection unavailable';
 const kCachedResultsLog =
     'The results of this example are taken from the Apache Beam Playground cache.\n';

Review Comment:
   Localize.



##########
playground/frontend/playground_components/lib/src/repositories/code_client/grpc_code_client.dart:
##########
@@ -18,10 +18,9 @@
 
 import 'package:grpc/grpc.dart';
 
+import '../../../playground_components.dart';

Review Comment:
   Import individual files.



##########
playground/frontend/playground_components/lib/src/repositories/code_client/grpc_code_client.dart:
##########
@@ -192,6 +194,11 @@ class GrpcCodeClient implements CodeClient {
     try {
       return await invoke();
     } on GrpcError catch (error) {
+      //TODO(Malarg): check if internet connection available here using connectivity_plus
+      //throw internet unavailable exception, if not
+      if (error.message?.contains('CORS') ?? false) {
+        throw const RunCodeError(message: kInternetConnectionUnavailable);
+      }

Review Comment:
   Check if this is a gRPC package bug, submit an issue there if so.



##########
playground/frontend/playground_components/lib/src/util/connectivity_result.dart:
##########
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import 'package:connectivity_plus/connectivity_plus.dart';
+
+extension ConnectivityResultExtension on ConnectivityResult {
+  bool get isConnected => [
+        ConnectivityResult.ethernet,
+        ConnectivityResult.mobile,
+        ConnectivityResult.vpn,
+        ConnectivityResult.wifi,
+      ].contains(this);

Review Comment:
   Check if != none.



##########
playground/frontend/playground_components/lib/src/repositories/models/run_code_result.dart:
##########
@@ -19,27 +19,27 @@
 import 'package:equatable/equatable.dart';
 
 enum RunCodeStatus {
-  unspecified,
-  preparation,
-  preparationError,
-  validationError,
-  compiling,
   compileError,
+  compiling,
   executing,
-  runError,
   finished,
+  preparation,
+  preparationError,
+  runError,
   timeout,
   unknownError,
+  unspecified,
+  validationError,

Review Comment:
   Revert because this mirrors the backend enum. Preserving the order allows to track if we added all statuses from there.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org