From d3fb5413ab13e3badf5d4300fe51caf860545ad1 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Sun, 31 Jan 2010 14:26:44 +0530 Subject: [PATCH] cleanup error codes --- oxdb/backend/views.py | 12 +++++++++--- oxdb/oxuser/views.py | 14 +++++++------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/oxdb/backend/views.py b/oxdb/backend/views.py index f878666b..c86030d4 100644 --- a/oxdb/backend/views.py +++ b/oxdb/backend/views.py @@ -47,7 +47,7 @@ def api(request): response = f(request) else: 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'] = '*' return response @@ -63,6 +63,12 @@ def api_hello(request): response['data']['user'] = {'name': 'Guest'} 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__'): order_by = [] @@ -359,7 +365,7 @@ def api_addArchive(request): data = json.loads(request.POST['data']) try: 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: archive = models.Archive(name=data['name']) archive.save() @@ -481,7 +487,7 @@ def api_parse(request): #parse path and return info ''' path = json.loads(request.POST['data'])['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) def api_getImdbId(request): diff --git a/oxdb/oxuser/views.py b/oxdb/oxuser/views.py index fd43592f..532e6e20 100644 --- a/oxdb/oxuser/views.py +++ b/oxdb/oxuser/views.py @@ -35,11 +35,11 @@ def api_login(request): user_json = models.getUserJSON(user) response = {'status': {'code': 200, 'message': 'You are logged in.', 'user': user_json}} else: - response = {'status': {'code': 403, 'text': 'Your account is disabled.'}} + response = {'status': {'code': 401, 'text': 'Your account is disabled.'}} else: - response = {'status': {'code': 403, 'text': 'Your username and password were incorrect.'}} + response = {'status': {'code': 401, 'text': 'Your username and password were incorrect.'}} else: - response = {'status': {'code':422, 'text': 'invalid data'}} + response = {'status': {'code': 400, 'text': 'invalid data'}} return render_to_json_response(response) @@ -71,9 +71,9 @@ def api_register(request): form = RegisterForm(data, request.FILES) if form.is_valid(): 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: - response = {'status': {'code':422, 'text': 'username or email exists'}} + response = {'status': {'code': 400, 'text': 'username or email exists'}} else: user = models.User(username=form.data['username'], email=form.data['email']) user.set_password(form.data['password']) @@ -83,7 +83,7 @@ def api_register(request): login(request, user) response = {'status': {'code':200, 'text': 'account created'}} else: - response = {'status': {'code':422, 'text': 'username exists'}} + response = {'status': {'code': 400, 'text': 'username exists'}} return render_to_json_response(response) class RecoverForm(forms.Form): @@ -115,7 +115,7 @@ def api_recover(request): else: response = {'status': {'code': 404, 'text': 'user or email not found.'}} else: - response = {'status': {'code':422, 'text': 'username exists'}} + response = {'status': {'code': 400, 'text': 'username exists'}} return render_to_json_response(response) @login_required_json