66from bevyframe .Widgets .Page import Page
77from bevyframe .Objects .Response import Response
88from bevyframe .Helpers .Identifiers import *
9- from bevyframe .Widgets .Widget import Widget
109
1110
1211def error_handler (self , request : Context , status_code : int , exception : str ) -> Response :
@@ -22,55 +21,43 @@ def error_handler(self, request: Context, status_code: int, exception: str) -> R
2221 resp .status_code = status_code
2322 return resp
2423 except :
24+ pwd = os .getcwd ()
2525 exception = exception .replace ('<' , '<' ).replace ('>' , '>' )
2626 t = exception .replace ('\n ' , '<br>' ).split ('<br> File' )
2727 e_boxes = [
28- Widget (
29- 'h1' ,
30- innertext = f'{ https_codes [status_code ]} '
31- )
28+ f'<h1>{ https_codes [status_code ]} </h1>'
3229 ]
3330 if 'Debugger' not in self .disabled and self .debug :
3431 if status_code == 500 :
3532 for e in t :
3633 if e .startswith ('Traceback' ):
37- e_boxes .append (
38- Widget (
39- 'div' ,
40- style = {'margin-bottom' : '10px' , 'padding-top' : '10px' , 'font-family' : 'monospace' },
41- innertext = e
42- )
43- )
34+ e_boxes .append (f'''
35+ <div style="margin-bottom: 10px; padding-top: 10px; font-family: monospace;">
36+ { e }
37+ </div>
38+ ''' )
4439 elif 'site-packages' in e :
45- e_boxes .append (
46- Widget (
47- 'div' ,
48- selector = 'the_box' ,
49- style = {'margin-bottom' : '10px' , 'padding-top' : '10px' , 'font-family' : 'monospace' },
50- innertext = (
51- 'Module ' +
52- e .split ('site-packages/' )[1 ].split ('/' )[0 ] + ', ' +
53- 'file ' +
54- e .split ('site-packages/' + e .split ('site-packages/' )[1 ].split ('/' )[0 ] + '/' )[
55- 1 ].split ('"' )[0 ] +
56- e .removeprefix (e .split (',' )[0 ])
57- )
58- )
59- )
60- else :
61- e_boxes .append (
62- Widget (
63- 'div' ,
64- selector = 'the_box' ,
65- style = {'margin-bottom' : '10px' , 'padding-top' : '10px' , 'font-family' : 'monospace' , 'overflow' : 'hidden' },
66- innertext = (
67- 'Path ' +
68- e .split ('"' )[1 ].removeprefix ('.' ).removesuffix ('/__init__.py' ).removeprefix (
69- os .getcwd ()) +
70- e .removeprefix (e .split ('"' )[0 ] + '"' + e .split ('"' )[1 ] + '"' )
71- )
72- )
73- )
40+ e_boxes .append (f'''
41+ <div
42+ class="the_box"
43+ style="margin-bottom: 10px; padding-top: 10px; font-family: monospace;" >
44+ Module
45+ { e .split ('site-packages/' )[1 ].split ('/' )[0 ]} ,
46+ file
47+ { e .split ('site-packages/' + e .split ('site-packages/' )[1 ].split ('/' )[0 ] + '/' )[1 ].split ('"' )[0 ]}
48+ { e .removeprefix (e .split (',' )[0 ])}
49+ </div>
50+ ''' )
51+ elif '/bevyframe/' not in e .split ('"' )[1 ].removeprefix (pwd ).removeprefix ('/pages/' ):
52+ e_boxes .append (f'''
53+ <div
54+ class="the_box"
55+ style="margin-bottom: 15px; padding: 20px; font-family: monospace; overflow: hidden" >
56+ { 'Path' if e .split ('"' )[1 ].startswith (pwd + '/pages/' ) else 'Script' }
57+ { e .split ('"' )[1 ].removeprefix (pwd ).removeprefix ('/pages/' ).removesuffix ('__init__.py' )}
58+ { e .removeprefix (e .split ('"' )[0 ] + '"' + e .split ('"' )[1 ] + '",' )}
59+ </div>
60+ ''' )
7461 else :
7562 print (exception )
7663 # noinspection PyBroadException
0 commit comments