Skip to content

Commit

Permalink
using my new errors
Browse files Browse the repository at this point in the history
  • Loading branch information
gtfierro committed Nov 22, 2024
1 parent 1bbb607 commit 3bf4a14
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
4 changes: 2 additions & 2 deletions buildingmotif/api/views/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
from flask import Blueprint, current_app, jsonify
from flask_api import status
from rdflib import URIRef
from sqlalchemy.orm.exc import NoResultFound

from buildingmotif.api.serializers.library import serialize
from buildingmotif.database.errors import LibraryNotFoundError, TemplateNotFoundError
from buildingmotif.dataclasses.shape_collection import ShapeCollection

blueprint = Blueprint("libraries", __name__)
Expand Down Expand Up @@ -81,7 +81,7 @@ def get_library(library_id: int) -> flask.Response:
"""
try:
db_lib = current_app.building_motif.table_connection.get_db_library(library_id)
except NoResultFound:
except LibraryNotFoundError:
return {
"message": f"No library with id {library_id}"
}, status.HTTP_404_NOT_FOUND
Expand Down
7 changes: 4 additions & 3 deletions buildingmotif/api/views/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from rdflib import Literal, URIRef
from rdflib.term import Node
from sqlalchemy.orm.exc import NoResultFound
from buildingmotif.database.errors import TemplateNotFoundError

from buildingmotif.api.serializers.template import serialize
from buildingmotif.dataclasses import Model, Template
Expand Down Expand Up @@ -42,7 +43,7 @@ def get_template(templates_id: int) -> flask.Response:
template = current_app.building_motif.table_connection.get_db_template(
templates_id
)
except NoResultFound:
except TemplateNotFoundError:
return {
"message": f"No template with id {templates_id}"
}, status.HTTP_404_NOT_FOUND
Expand All @@ -55,7 +56,7 @@ def evaluate_ingress(template_id: int) -> flask.Response:
# get template
try:
template = Template.load(template_id)
except NoResultFound:
except TemplateNotFoundError:
return {
"message": f"No template with id {template_id}"
}, status.HTTP_404_NOT_FOUND
Expand Down Expand Up @@ -107,7 +108,7 @@ def evaluate_bindings(template_id: int) -> flask.Response:
"""
try:
template = Template.load(template_id)
except NoResultFound:
except TemplateNotFoundError:
return {
"message": f"No template with id {template_id}"
}, status.HTTP_404_NOT_FOUND
Expand Down
5 changes: 3 additions & 2 deletions buildingmotif/dataclasses/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

from buildingmotif import get_building_motif
from buildingmotif.database.tables import DBLibrary, DBTemplate
from buildingmotif.database.errors import LibraryNotFoundError, TemplateNotFoundError
from buildingmotif.dataclasses.shape_collection import ShapeCollection
from buildingmotif.dataclasses.template import Template
from buildingmotif.schemas import validate_libraries_yaml
Expand Down Expand Up @@ -116,7 +117,7 @@ def create(cls, name: str, overwrite: Optional[bool] = True) -> "Library":
logging.warning(
f'Library {name} already exists in database. To ovewrite load library with "overwrite=True"' # noqa
)
except sqlalchemy.exc.NoResultFound:
except LibraryNotFoundError:
db_library = bm.table_connection.create_db_library(name)

return cls(_id=db_library.id, _name=db_library.name, _bm=bm)
Expand Down Expand Up @@ -445,7 +446,7 @@ def _library_exists(library_name: str) -> bool:
try:
bm.table_connection.get_db_library_by_name(library_name)
return True
except sqlalchemy.exc.NoResultFound:
except LibraryNotFoundError:
return False

def _resolve_dependency(
Expand Down
4 changes: 2 additions & 2 deletions buildingmotif/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from rdflib.compare import _TripleCanonicalizer
from rdflib.paths import ZeroOrOne
from rdflib.term import Node
from sqlalchemy.exc import NoResultFound
from buildingmotif.database.errors import TemplateNotFoundError, LibraryNotFoundError

from buildingmotif.namespaces import OWL, PARAM, RDF, SH, XSD, bind_prefixes

Expand Down Expand Up @@ -63,7 +63,7 @@ def _guarantee_unique_template_name(library: "Library", name: str) -> str:
while library.get_template_by_name(name):
name = f"{original_name}_{idx}"
idx += 1
except NoResultFound:
except LibraryNotFoundError:
# this means that the template does not exist and we can use the original name
pass
return name
Expand Down

0 comments on commit 3bf4a14

Please sign in to comment.