diff --git a/polytope_server/common/datasource/polytope.py b/polytope_server/common/datasource/polytope.py index 8a547f6..d2598a9 100644 --- a/polytope_server/common/datasource/polytope.py +++ b/polytope_server/common/datasource/polytope.py @@ -22,9 +22,9 @@ import logging import os -from polytope_mars.api import PolytopeMars - import yaml +from polytope.utility.exceptions import PolytopeError +from polytope_mars.api import PolytopeMars from . import datasource @@ -42,7 +42,7 @@ def __init__(self, config): self.config_file = "/tmp/gribjump.yaml" with open(self.config_file, "w") as f: f.write(yaml.dump(self.config["gribjump_config"])) - self.config['datacube']['config'] = self.config_file + self.config["datacube"]["config"] = self.config_file os.environ["GRIBJUMP_CONFIG_FILE"] = self.config_file self.polytope_options = self.config.get("polytope-options", {}) @@ -60,8 +60,12 @@ def retrieve(self, request): r = yaml.safe_load(request.user_request) logging.info(r) - self.output = self.polytope_mars.extract(r) - self.output = json.dumps(self.output).encode("utf-8") + try: + self.output = self.polytope_mars.extract(r) + self.output = json.dumps(self.output).encode("utf-8") + except PolytopeError as e: + self.output = json.dumps({"error": str(e)}).encode("utf-8") + raise e # logging.info(self.output) return True