This repository was archived by the owner on Nov 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathweb_server_is_down.py
More file actions
47 lines (34 loc) · 1.35 KB
/
web_server_is_down.py
File metadata and controls
47 lines (34 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from flask_utils.errors.base_class import _BaseFlaskException
class WebServerIsDownError(_BaseFlaskException):
"""This is the WebServerIsDownError exception class.
When raised, it will return a 521 status code with the message and solution provided.
:param msg: The message to be displayed in the error.
:param solution: The solution to the error.
:Example:
.. code-block:: python
from flask_utils.errors import WebServerIsDownError
# Inside a Flask route
@app.route('/example', methods=['POST'])
def example_route():
...
if some_condition:
raise WebServerIsDownError("The web server is down.")
The above code would return the following JSON response from Flask:
.. code-block:: json
{
"success": false,
"error": {
"type": "WebServerIsDownError",
"name": "Web Server Is Down",
"message": "The web server is down.",
"solution": "Try again later."
},
"code": 521
}
.. versionadded:: 0.1.0
"""
def __init__(self, msg: str, solution: str = "Try again later.") -> None:
self.name = "Web Server Is Down"
self.msg = msg
self.solution = solution
self.status_code = 521