Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
vidjil
vidjil
Commits
398d67a7
Commit
398d67a7
authored
Apr 11, 2015
by
Mathieu Giraud
Committed by
Vidjil Team
Apr 12, 2015
Browse files
controllers/default.py: rewrite default/error handler
parent
7277253f
Changes
1
Hide whitespace changes
Inline
Side-by-side
server/web2py/applications/vidjil/controllers/default.py
View file @
398d67a7
...
...
@@ -397,7 +397,7 @@ def save_analysis():
#########################################################################
def
handle_
error
():
def
error
():
"""
Custom error handler that returns correct status codes,
adapted from http://www.web2pyslices.com/slice/show/1529/custom-error-routing
...
...
@@ -405,25 +405,22 @@ def handle_error():
code
=
request
.
vars
.
code
request_url
=
request
.
vars
.
request_url
requested_uri
=
request
.
vars
.
requested_uri
ticket
=
request
.
vars
.
ticket
response
.
status
=
int
(
code
)
log
.
error
(
"[%s] %s"
%
(
code
,
ticket
))
assert
(
response
.
status
==
500
and
request_url
!=
request
.
url
)
# avoid infinite loop
if
code
is
not
None
and
request_url
!=
request
.
url
:
# Make sure error url is not current url to avoid infinite loop.
response
.
status
=
int
(
code
)
# Assign the error status code to the current response. (Must be integer to work.)
ticket_url
=
'<a href="https://%(host)s/admin/default/ticket/%(ticket)s">%(ticket)s</a>'
%
{
'host'
:
request
.
env
.
http_host
,
'ticket'
:
ticket
}
log
.
error
(
"Server error // %s"
%
ticket_url
)
if
code
==
'403'
:
return
"Not authorized"
elif
code
==
'404'
:
return
"Not found"
elif
code
==
'500'
:
# Get ticket URL:
ticket_url
=
"<a href='%(scheme)s://%(host)s/admin/default/ticket/%(ticket)s' target='_blank'>%(ticket)s</a>"
%
{
'scheme'
:
'https'
,
'host'
:
request
.
env
.
http_host
,
'ticket'
:
ticket
}
user_str
,
x
=
log
.
process
(
''
,
None
)
user_str
=
user_str
.
replace
(
'<'
,
''
).
replace
(
'>'
,
''
)
# Email a notice, etc:
mail
.
send
(
to
=
[
'contact@vidjil.org'
],
subject
=
"[Vidjil] web2py error"
,
message
=
"Error Ticket: %s"
%
ticket_url
)
mail
.
send
(
to
=
defs
.
ADMIN_EMAILS
,
subject
=
"[Vidjil] Server error - %s"
%
user_str
,
message
=
"<html>Ticket: %s<br/>At: %s<br />User: %s</html>"
%
(
ticket_url
,
requested_uri
,
user_str
))
return
"Server error"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment