]>
Commit | Line | Data |
---|---|---|
11fdf7f2 TL |
1 | # -*- coding: utf-8 -*- |
2 | from __future__ import absolute_import | |
3 | ||
4 | ||
5 | class ViewCacheNoDataException(Exception): | |
6 | def __init__(self): | |
7 | self.status = 200 | |
8 | super(ViewCacheNoDataException, self).__init__('ViewCache: unable to retrieve data') | |
9 | ||
10 | ||
11 | class DashboardException(Exception): | |
12 | """ | |
13 | Used for exceptions that are already handled and should end up as a user error. | |
14 | Or, as a replacement for cherrypy.HTTPError(...) | |
15 | ||
16 | Typically, you don't inherent from DashboardException | |
17 | """ | |
18 | ||
19 | # pylint: disable=too-many-arguments | |
20 | def __init__(self, e=None, code=None, component=None, http_status_code=None, msg=None): | |
21 | super(DashboardException, self).__init__(msg) | |
22 | self._code = code | |
23 | self.component = component | |
24 | if e: | |
25 | self.e = e | |
26 | if http_status_code: | |
27 | self.status = http_status_code | |
28 | else: | |
29 | self.status = 400 | |
30 | ||
31 | def __str__(self): | |
32 | try: | |
33 | return str(self.e) | |
34 | except AttributeError: | |
35 | return super(DashboardException, self).__str__() | |
36 | ||
37 | @property | |
38 | def errno(self): | |
39 | return self.e.errno | |
40 | ||
41 | @property | |
42 | def code(self): | |
43 | if self._code: | |
44 | return str(self._code) | |
9f95a23c | 45 | return str(abs(self.errno)) if self.errno is not None else 'Error' |
11fdf7f2 TL |
46 | |
47 | ||
48 | # access control module exceptions | |
49 | class RoleAlreadyExists(Exception): | |
50 | def __init__(self, name): | |
51 | super(RoleAlreadyExists, self).__init__( | |
52 | "Role '{}' already exists".format(name)) | |
53 | ||
54 | ||
55 | class RoleDoesNotExist(Exception): | |
56 | def __init__(self, name): | |
57 | super(RoleDoesNotExist, self).__init__( | |
58 | "Role '{}' does not exist".format(name)) | |
59 | ||
60 | ||
61 | class ScopeNotValid(Exception): | |
62 | def __init__(self, name): | |
63 | super(ScopeNotValid, self).__init__( | |
64 | "Scope '{}' is not valid".format(name)) | |
65 | ||
66 | ||
67 | class PermissionNotValid(Exception): | |
68 | def __init__(self, name): | |
69 | super(PermissionNotValid, self).__init__( | |
70 | "Permission '{}' is not valid".format(name)) | |
71 | ||
72 | ||
73 | class RoleIsAssociatedWithUser(Exception): | |
74 | def __init__(self, rolename, username): | |
75 | super(RoleIsAssociatedWithUser, self).__init__( | |
76 | "Role '{}' is still associated with user '{}'" | |
77 | .format(rolename, username)) | |
78 | ||
79 | ||
80 | class UserAlreadyExists(Exception): | |
81 | def __init__(self, name): | |
82 | super(UserAlreadyExists, self).__init__( | |
83 | "User '{}' already exists".format(name)) | |
84 | ||
85 | ||
86 | class UserDoesNotExist(Exception): | |
87 | def __init__(self, name): | |
88 | super(UserDoesNotExist, self).__init__( | |
89 | "User '{}' does not exist".format(name)) | |
90 | ||
91 | ||
92 | class ScopeNotInRole(Exception): | |
93 | def __init__(self, scopename, rolename): | |
94 | super(ScopeNotInRole, self).__init__( | |
95 | "There are no permissions for scope '{}' in role '{}'" | |
96 | .format(scopename, rolename)) | |
97 | ||
98 | ||
99 | class RoleNotInUser(Exception): | |
100 | def __init__(self, rolename, username): | |
101 | super(RoleNotInUser, self).__init__( | |
102 | "Role '{}' is not associated with user '{}'" | |
103 | .format(rolename, username)) | |
81eedcae TL |
104 | |
105 | ||
9f95a23c TL |
106 | class PwdExpirationDateNotValid(Exception): |
107 | def __init__(self): | |
108 | super(PwdExpirationDateNotValid, self).__init__( | |
109 | "The password expiration date must not be in the past") | |
110 | ||
111 | ||
81eedcae TL |
112 | class GrafanaError(Exception): |
113 | pass | |
9f95a23c TL |
114 | |
115 | ||
116 | class PasswordPolicyException(Exception): | |
117 | pass |