|
@@ -1,6 +1,7 @@
|
1
|
1
|
#-*- coding: utf-8 -*-
|
2
|
2
|
|
3
|
3
|
from werkzeug.wrappers import Response
|
|
4
|
+from lodel.context import LodelContext
|
4
|
5
|
|
5
|
6
|
class HttpException(Exception):
|
6
|
7
|
|
|
@@ -23,8 +24,23 @@ class HttpException(Exception):
|
23
|
24
|
self.status_code = status_code
|
24
|
25
|
self.tpl = tpl
|
25
|
26
|
self.custom = custom
|
|
27
|
+
|
|
28
|
+ ##@brief Log exception with lodel logger
|
|
29
|
+ def log(self):
|
|
30
|
+ LodelContext.expose_modules(globals(), {'lodel.logger': 'logger'})
|
|
31
|
+ msg = "Webui HTTP exception : %s" % self
|
|
32
|
+ if self.status_code / 100 == 4:
|
|
33
|
+ logger.security(msg)
|
|
34
|
+ elif self.status_code / 100 == 5:
|
|
35
|
+ logger.error(msg)
|
|
36
|
+ else:
|
|
37
|
+ logger.warning(msg)
|
|
38
|
+
|
|
39
|
+ def __str__(self):
|
|
40
|
+ return "HTTP:%d '%s'" % (self.status_code, self.custom)
|
26
|
41
|
|
27
|
42
|
def render(self, request):
|
|
43
|
+ self.log()
|
28
|
44
|
from .interface.template.loader import TemplateLoader
|
29
|
45
|
loader = TemplateLoader()
|
30
|
46
|
tpl_vars = {
|
|
@@ -55,7 +71,13 @@ class HttpErrors(HttpException):
|
55
|
71
|
custom = title)
|
56
|
72
|
self.errors = errors
|
57
|
73
|
|
|
74
|
+ def __str__(self):
|
|
75
|
+ ret = super().__str__()
|
|
76
|
+ ret += ', '.join([ '%s: %s' % val for val in self.errors.items()])
|
|
77
|
+ return ret
|
|
78
|
+
|
58
|
79
|
def render(self, request):
|
|
80
|
+ self.log()
|
59
|
81
|
from .interface.template.loader import TemplateLoader
|
60
|
82
|
loader = TemplateLoader()
|
61
|
83
|
tpl_vars = {
|