Skip to content
Snippets Groups Projects
Commit 49ef2569 authored by Simon Künzel's avatar Simon Künzel
Browse files

Add site_is_overloaded error code

parent 99b75708
No related branches found
No related tags found
1 merge request!2Rollout to production
Pipeline #5977 passed
# Specification of the Web API for the Video-AG Website (v0.51). # Specification of the Web API for the Video-AG Website (v0.52).
## Introduction ## Introduction
...@@ -1518,9 +1518,14 @@ Possible `error_code`: ...@@ -1518,9 +1518,14 @@ Possible `error_code`:
| too_many_suggestions | 403 | | | too_many_suggestions | 403 | |
| site_is_readonly | 503 | | | site_is_readonly | 503 | |
| site_is_disabled | 503 | | | site_is_disabled | 503 | |
| site_is_overloaded | 503 | |
## Changelog ## Changelog
### v0.52
* Added error code `site_is_overloaded`
### v0.51 ### v0.51
* Added `server_name` to `GET /status` * Added `server_name` to `GET /status`
......
...@@ -25,7 +25,8 @@ from api.miscellaneous.errors import (ApiError, ApiClientException, api_on_error ...@@ -25,7 +25,8 @@ from api.miscellaneous.errors import (ApiError, ApiClientException, api_on_error
ERROR_MODIFICATION_UNEXPECTED_CURRENT_VALUE, ERROR_MODIFICATION_UNEXPECTED_CURRENT_VALUE,
ERROR_TOO_MANY_SUGGESTIONS, ERROR_TOO_MANY_SUGGESTIONS,
ERROR_SITE_IS_READONLY, ERROR_SITE_IS_READONLY,
ERROR_SITE_IS_DISABLED) ERROR_SITE_IS_DISABLED,
ERROR_SITE_IS_OVERLOADED)
from api.miscellaneous.rate_limiter import IntervalRateLimiter, HostBasedCounterRateLimiter, create_configured_host_rate_limiters from api.miscellaneous.rate_limiter import IntervalRateLimiter, HostBasedCounterRateLimiter, create_configured_host_rate_limiters
from api.miscellaneous.diagnostics import DIAGNOSTICS_TRACKER, DiagnosticsCounter, DiagnosticsDataProvider from api.miscellaneous.diagnostics import DIAGNOSTICS_TRACKER, DiagnosticsCounter, DiagnosticsDataProvider
from api.miscellaneous.scheduler import scheduled_function from api.miscellaneous.scheduler import scheduled_function
......
...@@ -83,6 +83,8 @@ ERROR_SITE_IS_READONLY = ApiError("site_is_readonly", HTTP_503_SERVICE_UNAVAILAB ...@@ -83,6 +83,8 @@ ERROR_SITE_IS_READONLY = ApiError("site_is_readonly", HTTP_503_SERVICE_UNAVAILAB
"The site is currently in read-only mode") "The site is currently in read-only mode")
ERROR_SITE_IS_DISABLED = ApiError("site_is_disabled", HTTP_503_SERVICE_UNAVAILABLE, ERROR_SITE_IS_DISABLED = ApiError("site_is_disabled", HTTP_503_SERVICE_UNAVAILABLE,
"The site is currently disabled") "The site is currently disabled")
ERROR_SITE_IS_OVERLOADED = ApiError("site_is_overloaded", HTTP_503_SERVICE_UNAVAILABLE,
"Your request failed, as the site is currently experiencing a lot of traffic")
ALL_ERRORS_RANDOM = [ ALL_ERRORS_RANDOM = [
ERROR_BAD_REQUEST(), ERROR_BAD_REQUEST(),
...@@ -103,5 +105,6 @@ ALL_ERRORS_RANDOM = [ ...@@ -103,5 +105,6 @@ ALL_ERRORS_RANDOM = [
ERROR_OBJECT_ERROR("?"), ERROR_OBJECT_ERROR("?"),
ERROR_TOO_MANY_SUGGESTIONS, ERROR_TOO_MANY_SUGGESTIONS,
ERROR_SITE_IS_READONLY, ERROR_SITE_IS_READONLY,
ERROR_SITE_IS_DISABLED ERROR_SITE_IS_DISABLED,
ERROR_SITE_IS_OVERLOADED
] ]
...@@ -5,6 +5,7 @@ from re import Pattern ...@@ -5,6 +5,7 @@ from re import Pattern
import api import api
from api.authentication import is_moderator from api.authentication import is_moderator
from api.database.database import TransactionConflictError, NoAvailableConnectionError
from api.miscellaneous import * from api.miscellaneous import *
from api.version import get_api_path, API_LATEST_VERSION, API_OLDEST_ACTIVE_VERSION from api.version import get_api_path, API_LATEST_VERSION, API_OLDEST_ACTIVE_VERSION
...@@ -189,8 +190,12 @@ def api_function(track_in_diagnostics: bool = True, ...@@ -189,8 +190,12 @@ def api_function(track_in_diagnostics: bool = True,
raise Exception(f"Api route {truncate_string(request.path)} returned result of unknown type: {str(result)}") raise Exception(f"Api route {truncate_string(request.path)} returned result of unknown type: {str(result)}")
except ApiClientException as e: except ApiClientException as e:
return api_on_error(e.error) return api_on_error(e.error)
except (TransactionConflictError, NoAvailableConnectionError) as e:
print(f"An transaction conflict occurred while handling api request '{truncate_string(request.path, 200)}':")
traceback.print_exception(e)
return api_on_error(ERROR_SITE_IS_OVERLOADED)
except Exception as e: except Exception as e:
print("An exception occurred while handling api request:") print(f"An exception occurred while handling api request '{truncate_string(request.path, 200)}':")
traceback.print_exception(e) traceback.print_exception(e)
return api_on_error(ERROR_INTERNAL_SERVER_ERROR) return api_on_error(ERROR_INTERNAL_SERVER_ERROR)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment