Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
923bcc55
Commit
923bcc55
authored
Jun 20, 2013
by
David Baumgold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make CMS errors JSON-able if requested via AJAX
parent
ce6b3192
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
1 deletions
+26
-1
cms/djangoapps/contentstore/views/error.py
+26
-1
No files found.
cms/djangoapps/contentstore/views/error.py
View file @
923bcc55
from
django.http
import
HttpResponseServerError
,
HttpResponseNotFound
from
django.http
import
(
HttpResponse
,
HttpResponseServerError
,
HttpResponseNotFound
)
from
mitxmako.shortcuts
import
render_to_string
,
render_to_response
import
functools
import
json
__all__
=
[
'not_found'
,
'server_error'
,
'render_404'
,
'render_500'
]
def
jsonable_error
(
status
=
500
,
message
=
"The Studio servers encountered an error"
):
"""
A decorator to make an error view return an JSON-formatted message if
it was requested via AJAX.
"""
def
outer
(
func
):
@functools.wraps
(
func
)
def
inner
(
request
,
*
args
,
**
kwargs
):
if
request
.
is_ajax
():
content
=
json
.
dumps
({
"error"
:
message
})
return
HttpResponse
(
content
,
content_type
=
"application/json"
,
status
=
status
)
else
:
return
func
(
request
,
*
args
,
**
kwargs
)
return
inner
return
outer
@jsonable_error
(
404
,
"Resource not found"
)
def
not_found
(
request
):
return
render_to_response
(
'error.html'
,
{
'error'
:
'404'
})
@jsonable_error
(
500
,
"The Studio servers encountered an error"
)
def
server_error
(
request
):
return
render_to_response
(
'error.html'
,
{
'error'
:
'500'
})
@jsonable_error
(
404
,
"Resource not found"
)
def
render_404
(
request
):
return
HttpResponseNotFound
(
render_to_string
(
'404.html'
,
{}))
@jsonable_error
(
500
,
"The Studio servers encountered an error"
)
def
render_500
(
request
):
return
HttpResponseServerError
(
render_to_string
(
'500.html'
,
{}))
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