Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NO-REF: Using exception for logging API errors #381

Merged
merged 2 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions api/blueprints/drbCitation.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ def get_citation(uuid):
output_citations[format] = mla_citation

return APIUtils.formatResponseObject(200, response_type, output_citations)
except Exception as e:
logger.error(e)
except Exception:
logger.exception(f'Unable to get citation for work with id {uuid}')
return APIUtils.formatResponseObject(500, response_type, { 'message': f'Unable to get citation for work with id {uuid}' })


Expand Down
8 changes: 4 additions & 4 deletions api/blueprints/drbCollection.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,8 @@ def get_collection(uuid):
return APIUtils.formatOPDS2Object(200, opds_feed)
except NoResultFound:
return APIUtils.formatResponseObject(404, response_type, { 'message': f'No collection found with id {uuid}' })
except Exception as e:
logger.error(e)
except Exception:
logger.exception(f'Unable to get collection with id {uuid}')
return APIUtils.formatResponseObject(500, response_type, { 'message': f'Unable to get collection with id {uuid}' })

@collection.route('/<uuid>', methods=['DELETE'])
Expand Down Expand Up @@ -400,8 +400,8 @@ def get_collections():
db_client.closeSession()

return APIUtils.formatOPDS2Object(200, opds_feed)
except Exception as e:
logger.error(e)
except Exception:
logger.exception('Unable to get collections')
return APIUtils.formatResponseObject(500, response_type, { 'message': 'Unable to get collections' })


Expand Down
4 changes: 2 additions & 2 deletions api/blueprints/drbEdition.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ def get_edition(edition_id):
edition, request=request, records=records, dbClient=db_client, showAll=show_all, formats=filtered_formats, reader=reader_version
)
)
except Exception as e:
logger.error(e)
except Exception:
logger.exception(f'Unable to get edition with id {edition_id}')
return APIUtils.formatResponseObject(500, response_type, { 'message': f'Unable to get edition with id {edition_id}' })
4 changes: 2 additions & 2 deletions api/blueprints/drbFulfill.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ def fulfill_item(link_id):

if requires_authorization:
return redirect_to_link_url(link.url)
except Exception as e:
logger.error(e)
except Exception:
logger.exception(f'Unable to fulfill link with id {link_id}')
return APIUtils.formatResponseObject(
500,
response_type,
Expand Down
4 changes: 2 additions & 2 deletions api/blueprints/drbLink.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ def get_link(link_id):
response_type,
APIUtils.formatLinkOutput(link, request=request)
)
except Exception as e:
logger.error(e)
except Exception:
logger.exception(f'Unable to get link with id {link_id}')
return APIUtils.formatResponseObject(
500,
response_type,
Expand Down
6 changes: 3 additions & 3 deletions api/blueprints/drbSearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def query():
try:
search_result = es_client.searchQuery(terms, page=search_page, perPage=search_size)
except ElasticClientError as e:
logger.error(e)
logger.exception('Unable to execute search')
return APIUtils.formatResponseObject(500, response_type, { 'message': 'Unable to execute search' })

results = []
Expand Down Expand Up @@ -82,6 +82,6 @@ def query():
db_client.closeSession()

return APIUtils.formatResponseObject(200, response_type, data_block)
except Exception as e:
logger.error(e)
except Exception:
logger.exception('Unable to execute search')
return APIUtils.formatResponseObject(500, response_type, { 'message': 'Unable to execute search' })
10 changes: 5 additions & 5 deletions api/blueprints/drbUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ def get_languages():
response_type,
APIUtils.formatLanguages(language_query_results.aggregations, work_counts)
)
except Exception as e:
logger.error(e)
except Exception:
logger.exception('Unable to get language counts')
return APIUtils.formatResponseObject(500, response_type, 'Unable to get language counts')


Expand All @@ -52,8 +52,8 @@ def get_counts():
total_counts = db_client.fetchRowCounts()

return APIUtils.formatResponseObject(200, response_type, APIUtils.formatTotals(total_counts))
except Exception as e:
logger.error(e)
except Exception:
logger.exception('Unable to get total counts')
return APIUtils.formatResponseObject(500, response_type, 'Unable to get total counts')


Expand Down Expand Up @@ -105,5 +105,5 @@ def proxy_response():

return Response(response.content, response.status_code, headers)
except Exception as e:
logger.error(e)
logger.exception('Unable to proxy response')
return Response('Unable to proxy response', 500)
4 changes: 2 additions & 2 deletions api/blueprints/drbWork.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ def get_work(uuid):
request=request, dbClient=db_client, formats=filtered_formats, reader=reader_version
)
)
except Exception as e:
logger.error(e)
except Exception:
logger.exception(f'Unable to get work with id {uuid}')
return APIUtils.formatResponseObject(500, response_type, { 'message': f'Unable to get work with id {uuid}' })
2 changes: 1 addition & 1 deletion tests/unit/test_api_utils_blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from api.utils import APIUtils


class TestEditionBlueprint:
class TestUtilsBlueprint:
@pytest.fixture
def mock_utils(self, mocker):
return mocker.patch.multiple(
Expand Down
Loading