diff --git a/db/database.py b/db/database.py index 34c22ca..a9c6d41 100644 --- a/db/database.py +++ b/db/database.py @@ -3,6 +3,7 @@ import psycopg2 import pandas as pd from psycopg2.extras import RealDictCursor from psycopg2.extras import execute_batch, Json +from server.exceptions import NotExistentDatasetException class PostgresConnector: @@ -133,7 +134,7 @@ class PostgresConnector: if result: return pd.DataFrame(result) - raise ValueError("Dataset does not exist") + raise NotExistentDatasetException("Dataset does not exist") def get_dataset_info(self, dataset_id: int) -> dict: query = "SELECT * FROM datasets WHERE id = %s" @@ -141,7 +142,7 @@ class PostgresConnector: if result: return result[0] - raise ValueError("Dataset does not exist") + raise NotExistentDatasetException("Dataset does not exist") def close(self): if self.connection: diff --git a/server/app.py b/server/app.py index 7f10872..5e63acd 100644 --- a/server/app.py +++ b/server/app.py @@ -13,7 +13,7 @@ from flask_jwt_extended import ( from server.stat_gen import StatGen from server.dataset_processor import DatasetProcessor -from server.exceptions import NotAuthorisedException +from server.exceptions import NotAuthorisedException, NotExistentDatasetException from db.database import PostgresConnector from server.auth import AuthManager from server.utils import get_request_filters, get_dataset_and_validate @@ -160,7 +160,10 @@ def get_dataset(dataset_id): return jsonify(filtered_dataset), 200 except NotAuthorisedException: return jsonify({"error": "User is not authorised to access this content"}), 403 + except NotExistentDatasetException: + return jsonify({"error": "Dataset does not exist"}), 404 except Exception: + print(traceback.format_exc()) return jsonify({"error": "An unexpected error occured"}), 500 diff --git a/server/exceptions.py b/server/exceptions.py index 9ecbd4f..f3ebaa9 100644 --- a/server/exceptions.py +++ b/server/exceptions.py @@ -1,2 +1,5 @@ class NotAuthorisedException(Exception): + pass + +class NotExistentDatasetException(Exception): pass \ No newline at end of file