Skip to content

Commit

Permalink
Partial cherry-pick from 24b8a6b to fix excessive logging (Fixes #1021)
Browse files Browse the repository at this point in the history
  • Loading branch information
baszoetekouw committed Nov 1, 2023
1 parent 5eee35c commit 2fe9ea1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
9 changes: 7 additions & 2 deletions server/api/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from flask import Blueprint, jsonify, current_app, request as current_request, session, g as request_context
from jsonschema import ValidationError
from sqlalchemy.orm.exc import NoResultFound
from werkzeug.exceptions import HTTPException, Unauthorized, BadRequest, Forbidden
from werkzeug.exceptions import HTTPException, Unauthorized, BadRequest, Forbidden, Conflict

from server.api.exceptions import APIBadRequest
from server.auth.security import current_user_id, CSRF_TOKEN
Expand Down Expand Up @@ -204,6 +204,8 @@ def wrapper(*args, **kwargs):
e.description = f"Unauthorized 401: {current_request.url}. IP: {_remote_address()}"
elif isinstance(e, APIBadRequest):
skip_email = True
elif isinstance(e, Conflict):
skip_email = True
elif isinstance(e, MySQLdb.IntegrityError):
skip_email = True
elif hasattr(e, "description"):
Expand All @@ -222,7 +224,10 @@ def wrapper(*args, **kwargs):
_add_custom_header(response)
db.session.rollback()
# We want to send emails if the exception is unexpected and validation errors should not happen server-side
ctx_logger("base").exception(response)
if isinstance(e, Conflict):
ctx_logger("base").info(response)
else:
ctx_logger("base").exception(response)
if not skip_email and (response.status_code == 500 or response.status_code == 400):
send_error_mail(tb=traceback.format_exc())
return response
Expand Down
4 changes: 2 additions & 2 deletions server/api/collaborations_services.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from flasgger import swag_from
from flask import Blueprint, request as current_request, g as request_context
from werkzeug.exceptions import BadRequest, Forbidden
from werkzeug.exceptions import BadRequest, Forbidden, Conflict

from server.api.base import json_endpoint, emit_socket
from server.api.service_group import create_service_groups
Expand Down Expand Up @@ -132,7 +132,7 @@ def disconnect_collaboration_service_api():
if service in collaboration.services:
collaboration.services.remove(service)
else:
raise BadRequest(f"Service {service_entity_id} is not connected to collaboration {collaboration.name}")
raise Conflict(f"Service {service_entity_id} is not connected to collaboration {collaboration.name}")

update_last_activity_date(collaboration_id)

Expand Down
2 changes: 1 addition & 1 deletion server/test/api/test_collaborations_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,6 @@ def test_disconnect_collaboration_service_not_connected(self):
"short_name": collaboration.short_name,
"service_entity_id": service.entity_id
}), content_type="application/json")
self.assertEqual(res.status_code, 400)
self.assertEqual(res.status_code, 409)
error_dict = res.json
self.assertTrue("is not connected to collaboration" in error_dict["message"])

0 comments on commit 2fe9ea1

Please sign in to comment.