Commit d5a88729 authored by Wei Shoulin's avatar Wei Shoulin
Browse files

refactor(catalog): update error handling and pandas import logic

parent 9ac0f71c
Pipeline #11178 failed with stages
in 0 seconds
...@@ -37,6 +37,7 @@ def search(ra: float, ...@@ -37,6 +37,7 @@ def search(ra: float,
columns = ['*'] columns = ['*']
try: try:
import pandas as pd
datas = request.post('/api/catalog', { datas = request.post('/api/catalog', {
'ra': ra, 'ra': ra,
'dec': dec, 'dec': dec,
...@@ -74,6 +75,8 @@ def all_catalog_names() -> Result: ...@@ -74,6 +75,8 @@ def all_catalog_names() -> Result:
return datas return datas
records = pickle.loads(datas._content) records = pickle.loads(datas._content)
return Result.ok_data(data = records) return Result.ok_data(data = records)
except ImportError:
return Result.error("pandas is not installed")
except Exception as e: except Exception as e:
return Result.error(str(e)) return Result.error(str(e))
...@@ -89,10 +92,13 @@ def describe_catalog(catalog_name: str) -> Result: ...@@ -89,10 +92,13 @@ def describe_catalog(catalog_name: str) -> Result:
""" """
try: try:
import pandas as pd
datas = request.get(f'/api/catalog/describe/{catalog_name}') datas = request.get(f'/api/catalog/describe/{catalog_name}')
if datas and isinstance(datas, Result): if datas and isinstance(datas, Result):
return datas return datas
records = pickle.loads(datas._content) records = pickle.loads(datas._content)
return Result.ok_data(data = records) return Result.ok_data(data = records)
except ImportError:
return Result.error("pandas is not installed")
except Exception as e: except Exception as e:
return Result.error(str(e)) return Result.error(str(e))
...@@ -30,9 +30,9 @@ class Result(dict): ...@@ -30,9 +30,9 @@ class Result(dict):
return str(self["message"]) return str(self["message"])
@staticmethod @staticmethod
def error(code: int = 500, message: str = "") -> "Result": def error(message: str = "") -> "Result":
r = Result() r = Result()
r["code"] = code r["code"] = 500
r["message"] = message r["message"] = message
return r return r
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment