Commit 863193cb authored by Sofia Papagiannaki's avatar Sofia Papagiannaki
Browse files

change api faults

Refs: #1958
parent 49df775e
......@@ -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 (503)
# Error Response Codes: internalServerError (500)
# 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)
......@@ -47,5 +47,5 @@ class BadRequest(Fault):
class Unauthorized(Fault):
code = 401
class ServiceUnavailable(Fault):
code = 503
class InternalServerError(Fault):
code = 500
......@@ -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
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment