Revision 863193cb

b/astakos/im/api.py
37 37
from django.http import HttpResponse
38 38
from django.utils import simplejson as json
39 39

  
40
from astakos.im.faults import BadRequest, Unauthorized, ServiceUnavailable
40
from astakos.im.faults import BadRequest, Unauthorized, InternalServerError
41 41
from astakos.im.models import AstakosUser
42 42

  
43 43
def render_fault(request, fault):
44
    if settings.DEBUG or settings.TEST:
44
    if isinstance(fault, InternalServerError) and (settings.DEBUG or settings.TEST):
45 45
        fault.details = format_exc(fault)
46 46
    
47 47
    request.serialization = 'text'
48
    data = '\n'.join((fault.message, fault.details)) + '\n'
48
    data = fault.message + '\n'
49
    if fault.details:
50
        data += '\n' + fault.details
49 51
    response = HttpResponse(data, status=fault.code)
50
    return response
51

  
52
def update_response_headers(response):
53
    response['Content-Type'] = 'application/json; charset=UTF-8'
54 52
    response['Content-Length'] = len(response.content)
53
    return response
55 54

  
56 55
def authenticate(request):
57 56
    # Normal Response Codes: 204
58
    # Error Response Codes: serviceUnavailable (503)
57
    # Error Response Codes: internalServerError (500)
59 58
    #                       badRequest (400)
60 59
    #                       unauthorised (401)
61 60
    try:
......
86 85
                     'auth_token_created':user.auth_token_created.isoformat(),
87 86
                     'auth_token_expires':user.auth_token_expires.isoformat()}
88 87
        response.content = json.dumps(user_info)
89
        update_response_headers(response)
88
        response['Content-Type'] = 'application/json; charset=UTF-8'
89
        response['Content-Length'] = len(response.content)
90 90
        return response
91 91
    except BaseException, e:
92
        fault = ServiceUnavailable('Unexpected error')
92
        fault = InternalServerError('Unexpected error')
93 93
        return render_fault(request, fault)
b/astakos/im/faults.py
47 47
class Unauthorized(Fault):
48 48
    code = 401
49 49

  
50
class ServiceUnavailable(Fault):
51
    code = 503
50
class InternalServerError(Fault):
51
    code = 500
b/docs/source/devguide.rst
108 108

  
109 109
|
110 110

  
111
=========================  =====================
112
Return Code                Description
113
=========================  =====================
114
204 (No Content)           The request succeeded
115
400 (Bad Request)          The request is invalid
116
401 (Unauthorized)         Missing token or inactive user
117
503 (Service Unavailable)  The request cannot be completed because of an internal error
118
=========================  =====================
119

  
120
The Astakos views
121
-----------------
122

  
123
Astakos incorporates the ``django.contrib.auth`` mechanism for handling user login,
124
logout, password change and password reset.
125

  
126
==============================  =====================
127
Uri                             view
128
==============================  =====================
111
=========================== =====================
112
Return Code                 Description
113
=========================== =====================
114
204 (No Content)            The request succeeded
115
400 (Bad Request)           The request is invalid
116
401 (Unauthorized)          Missing token or inactive user
117
500 (Internal Server Error) The request cannot be completed because of an internal error
118
=========================== =====================

Also available in: Unified diff