forked from 0x2620/pandora
cleanup error codes
This commit is contained in:
parent
38bdb3b043
commit
d3fb5413ab
2 changed files with 16 additions and 10 deletions
|
@ -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):
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue