cleanup error codes

This commit is contained in:
j 2010-01-31 14:26:44 +05:30
parent 38bdb3b043
commit d3fb5413ab
2 changed files with 16 additions and 10 deletions

View file

@ -47,7 +47,7 @@ def api(request):
response = f(request) response = f(request)
else: else:
response = render_to_json_response( response = render_to_json_response(
{'status': {'code': 404, 'text': 'Unknown function %s' % function}}) {'status': {'code': 400, 'text': 'Unknown function %s' % function}})
#response['Access-Control-Allow-Origin'] = '*' #response['Access-Control-Allow-Origin'] = '*'
return response return response
@ -63,6 +63,12 @@ def api_hello(request):
response['data']['user'] = {'name': 'Guest'} response['data']['user'] = {'name': 'Guest'}
return render_to_json_response(response) return render_to_json_response(response)
def api_error(request):
'''
trows 503 error
'''
this = is_an_error
return render_to_json_response({})
def _order_query(qs, s, prefix='sort__'): def _order_query(qs, s, prefix='sort__'):
order_by = [] order_by = []
@ -359,7 +365,7 @@ def api_addArchive(request):
data = json.loads(request.POST['data']) data = json.loads(request.POST['data'])
try: try:
archive = models.Archive.objects.get(name=data['name']) archive = models.Archive.objects.get(name=data['name'])
response = {'status': {'code': 403, 'text': 'archive with this name exists'}} response = {'status': {'code': 401, 'text': 'archive with this name exists'}}
except models.Archive.DoesNotExist: except models.Archive.DoesNotExist:
archive = models.Archive(name=data['name']) archive = models.Archive(name=data['name'])
archive.save() archive.save()
@ -481,7 +487,7 @@ def api_parse(request): #parse path and return info
''' '''
path = json.loads(request.POST['data'])['path'] path = json.loads(request.POST['data'])['path']
response = utils.parsePath(path) response = utils.parsePath(path)
response = {'status': {'code': 500, 'text': 'ok'}, data: response} response = {'status': {'code': 200, 'text': 'ok'}, data: response}
return render_to_json_response(response) return render_to_json_response(response)
def api_getImdbId(request): def api_getImdbId(request):

View file

@ -35,11 +35,11 @@ def api_login(request):
user_json = models.getUserJSON(user) user_json = models.getUserJSON(user)
response = {'status': {'code': 200, 'message': 'You are logged in.', 'user': user_json}} response = {'status': {'code': 200, 'message': 'You are logged in.', 'user': user_json}}
else: else:
response = {'status': {'code': 403, 'text': 'Your account is disabled.'}} response = {'status': {'code': 401, 'text': 'Your account is disabled.'}}
else: else:
response = {'status': {'code': 403, 'text': 'Your username and password were incorrect.'}} response = {'status': {'code': 401, 'text': 'Your username and password were incorrect.'}}
else: else:
response = {'status': {'code':422, 'text': 'invalid data'}} response = {'status': {'code': 400, 'text': 'invalid data'}}
return render_to_json_response(response) return render_to_json_response(response)
@ -71,9 +71,9 @@ def api_register(request):
form = RegisterForm(data, request.FILES) form = RegisterForm(data, request.FILES)
if form.is_valid(): if form.is_valid():
if models.User.objects.filter(username=form.data['username']).count() > 0: if models.User.objects.filter(username=form.data['username']).count() > 0:
response = {'status': {'code':422, 'text': 'username or email exists'}} response = {'status': {'code': 400, 'text': 'username or email exists'}}
elif models.User.objects.filter(email=form.data['email']).count() > 0: elif models.User.objects.filter(email=form.data['email']).count() > 0:
response = {'status': {'code':422, 'text': 'username or email exists'}} response = {'status': {'code': 400, 'text': 'username or email exists'}}
else: else:
user = models.User(username=form.data['username'], email=form.data['email']) user = models.User(username=form.data['username'], email=form.data['email'])
user.set_password(form.data['password']) user.set_password(form.data['password'])
@ -83,7 +83,7 @@ def api_register(request):
login(request, user) login(request, user)
response = {'status': {'code':200, 'text': 'account created'}} response = {'status': {'code':200, 'text': 'account created'}}
else: else:
response = {'status': {'code':422, 'text': 'username exists'}} response = {'status': {'code': 400, 'text': 'username exists'}}
return render_to_json_response(response) return render_to_json_response(response)
class RecoverForm(forms.Form): class RecoverForm(forms.Form):
@ -115,7 +115,7 @@ def api_recover(request):
else: else:
response = {'status': {'code': 404, 'text': 'user or email not found.'}} response = {'status': {'code': 404, 'text': 'user or email not found.'}}
else: else:
response = {'status': {'code':422, 'text': 'username exists'}} response = {'status': {'code': 400, 'text': 'username exists'}}
return render_to_json_response(response) return render_to_json_response(response)
@login_required_json @login_required_json