#94 Utility exception handler
diff --git a/python-cli/mft_cli/airavata_mft_cli/base.py b/python-cli/mft_cli/airavata_mft_cli/base.py
index 92d28bd..1d1e2d3 100644
--- a/python-cli/mft_cli/airavata_mft_cli/base.py
+++ b/python-cli/mft_cli/airavata_mft_cli/base.py
@@ -19,8 +19,7 @@
import typer
import airavata_mft_cli.operations as operations
import airavata_mft_cli.bootstrap as bootstrap
-import grpc
-from rich import print
+from airavata_mft_cli.util import exception_handler
app = typer.Typer()
@@ -28,17 +27,15 @@
def list(storage_path):
try:
operations.list(storage_path)
- except grpc.RpcError as rpc_error:
- if rpc_error.code() == grpc.StatusCode.UNAVAILABLE:
- print(f'Could not list resources for your storage path {storage_path} due to MFT server unavailable')
+ except Exception as e:
+ exception_handler(e)
@app.command("cp")
def copy(source, destination):
try:
operations.copy(source, destination)
- except grpc.RpcError as rpc_error:
- if rpc_error.code() == grpc.StatusCode.UNAVAILABLE:
- print(f'Could not copy resources from source = {source} to destination = {destination} due to MFT server unavailable')
+ except Exception as e:
+ exception_handler(e)
@app.command("init")
def init_mft():
diff --git a/python-cli/mft_cli/airavata_mft_cli/storage/__init__.py b/python-cli/mft_cli/airavata_mft_cli/storage/__init__.py
index cb6b8b6..d461682 100644
--- a/python-cli/mft_cli/airavata_mft_cli/storage/__init__.py
+++ b/python-cli/mft_cli/airavata_mft_cli/storage/__init__.py
@@ -30,9 +30,9 @@
from rich.table import Table
from rich import print
import sys
-import grpc
sys.path.append('../airavata_mft_cli')
from airavata_mft_cli import config as configcli
+from airavata_mft_cli.util import exception_handler
app = typer.Typer()
@@ -54,9 +54,8 @@
swift.handle_add_storage()
elif option == "SCP":
scp.handle_add_storage()
- except grpc.RpcError as rpc_error:
- if rpc_error.code() == grpc.StatusCode.UNAVAILABLE:
- print(f'Could not add storage in {option} due to MFT server grpc unavailable error')
+ except Exception as e:
+ exception_handler(e)
@app.command("list")
def list_storage():
@@ -85,6 +84,5 @@
storage.storageId)
console.print(table)
- except grpc.RpcError as rpc_error:
- if rpc_error.code() == grpc.StatusCode.UNAVAILABLE:
- print('Could not fetch storage list due to MFT server grpc unavailable error')
+ except Exception as e:
+ exception_handler(e)
\ No newline at end of file
diff --git a/python-cli/mft_cli/airavata_mft_cli/util.py b/python-cli/mft_cli/airavata_mft_cli/util.py
new file mode 100644
index 0000000..186a6b5
--- /dev/null
+++ b/python-cli/mft_cli/airavata_mft_cli/util.py
@@ -0,0 +1,26 @@
+#
+# 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.
+#
+
+from rich import print
+import grpc
+
+def exception_handler(e):
+ if isinstance(e, grpc.RpcError):
+ if e.code() == grpc.StatusCode.UNAVAILABLE:
+ print(f"MFT server is unavailable")