Coverage for bundesliga_tippspiel/exceptions.py: 54%
Shortcuts on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1"""LICENSE
2Copyright 2017 Hermann Krumrey <hermann@krumreyh.com>
4This file is part of bundesliga-tippspiel.
6bundesliga-tippspiel is free software: you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation, either version 3 of the License, or
9(at your option) any later version.
11bundesliga-tippspiel is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
16You should have received a copy of the GNU General Public License
17along with bundesliga-tippspiel. If not, see <http://www.gnu.org/licenses/>.
18LICENSE"""
20from flask import flash
21from jerrycan.enums import AlertSeverity
24class ActionException(Exception):
25 """
26 An exception that gets raised whenever an action method fails for whatever
27 reason. The reason should be provided as a parameter
28 """
30 def __init__(
31 self, reason: str, display_message: str,
32 status_code: int = 400,
33 severity: AlertSeverity = AlertSeverity.DANGER
34 ):
35 """
36 Initializes the Exception while adding the 'reason' variable
37 :param reason: The reason for the exception
38 :param display_message: The message to display
39 :param status_code: The status code corresponding to the exception
40 Defaults to 400
41 :param severity: The severity of the exception. Defaults to DANGER
42 """
43 super().__init__(reason)
44 self.reason = reason
45 self.display_message = display_message
46 self.status_code = status_code
47 self.severity = severity
49 def flash(self):
50 """
51 Flashes the message so that it can be displayed on the next redirect
52 :return: None
53 """
54 flash(self.display_message, self.severity.value)