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
itminedu
synnefo
Commits
863193cb
Commit
863193cb
authored
Feb 06, 2012
by
Sofia Papagiannaki
Browse files
change api faults
Refs: #1958
parent
49df775e
Changes
3
Hide whitespace changes
Inline
Side-by-side
astakos/im/api.py
View file @
863193cb
...
...
@@ -37,25 +37,24 @@ from django.conf import settings
from
django.http
import
HttpResponse
from
django.utils
import
simplejson
as
json
from
astakos.im.faults
import
BadRequest
,
Unauthorized
,
ServiceUnavailable
from
astakos.im.faults
import
BadRequest
,
Unauthorized
,
InternalServerError
from
astakos.im.models
import
AstakosUser
def
render_fault
(
request
,
fault
):
if
settings
.
DEBUG
or
settings
.
TEST
:
if
isinstance
(
fault
,
InternalServerError
)
and
(
settings
.
DEBUG
or
settings
.
TEST
)
:
fault
.
details
=
format_exc
(
fault
)
request
.
serialization
=
'text'
data
=
'
\n
'
.
join
((
fault
.
message
,
fault
.
details
))
+
'
\n
'
data
=
fault
.
message
+
'
\n
'
if
fault
.
details
:
data
+=
'
\n
'
+
fault
.
details
response
=
HttpResponse
(
data
,
status
=
fault
.
code
)
return
response
def
update_response_headers
(
response
):
response
[
'Content-Type'
]
=
'application/json; charset=UTF-8'
response
[
'Content-Length'
]
=
len
(
response
.
content
)
return
response
def
authenticate
(
request
):
# Normal Response Codes: 204
# Error Response Codes:
serviceUnavailable
(50
3
)
# Error Response Codes:
internalServerError
(50
0
)
# badRequest (400)
# unauthorised (401)
try
:
...
...
@@ -86,8 +85,9 @@ def authenticate(request):
'auth_token_created'
:
user
.
auth_token_created
.
isoformat
(),
'auth_token_expires'
:
user
.
auth_token_expires
.
isoformat
()}
response
.
content
=
json
.
dumps
(
user_info
)
update_response_headers
(
response
)
response
[
'Content-Type'
]
=
'application/json; charset=UTF-8'
response
[
'Content-Length'
]
=
len
(
response
.
content
)
return
response
except
BaseException
,
e
:
fault
=
ServiceUnavailable
(
'Unexpected error'
)
fault
=
InternalServerError
(
'Unexpected error'
)
return
render_fault
(
request
,
fault
)
astakos/im/faults.py
View file @
863193cb
...
...
@@ -47,5 +47,5 @@ class BadRequest(Fault):
class
Unauthorized
(
Fault
):
code
=
401
class
ServiceUnavailable
(
Fault
):
code
=
50
3
class
InternalServerError
(
Fault
):
code
=
50
0
docs/source/devguide.rst
View file @
863193cb
...
...
@@ -108,21 +108,11 @@ Example reply:
|
========================= =====================
Return Code Description
========================= =====================
204 (No Content) The request succeeded
400 (Bad Request) The request is invalid
401 (Unauthorized) Missing token or inactive user
503 (Service Unavailable) The request cannot be completed because of an internal error
========================= =====================
The Astakos views
-----------------
Astakos incorporates the ``django.contrib.auth`` mechanism for handling user login,
logout, password change and password reset.
============================== =====================
Uri view
============================== =====================
=========================== =====================
Return Code Description
=========================== =====================
204 (No Content) The request succeeded
400 (Bad Request) The request is invalid
401 (Unauthorized) Missing token or inactive user
500 (Internal Server Error) The request cannot be completed because of an internal error
=========================== =====================
\ No newline at end of file
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