ソースを参照

return appropriate HTTP error code (api) #377

version-14
Rushabh Mehta 11年前
コミット
7fa4ef9593
4個のファイルの変更48行の追加41行の削除
  1. +4
    -5
      webnotes/app.py
  2. +19
    -16
      webnotes/handler.py
  3. +6
    -5
      webnotes/public/js/wn/request.js
  4. +19
    -15
      webnotes/templates/includes/login.js

+ 4
- 5
webnotes/app.py ファイルの表示

@@ -54,11 +54,7 @@ def application(request):
for k, v in (request.form or request.args).iteritems() })
webnotes.local._response = Response()

try:
webnotes.http_request = webnotes.auth.HTTPRequest()
except webnotes.AuthenticationError, e:
pass
webnotes.http_request = webnotes.auth.HTTPRequest()

if webnotes.form_dict.cmd:
webnotes.handler.handle()
@@ -70,6 +66,9 @@ def application(request):
except HTTPException, e:
return e
except webnotes.AuthenticationError, e:
webnotes._response.status_code=401
except webnotes.SessionStopped, e:
webnotes.local._response = handle_session_stopped()


+ 19
- 16
webnotes/handler.py ファイルの表示

@@ -68,30 +68,33 @@ def uploadfile():
def handle():
"""handle request"""
cmd = webnotes.form_dict['cmd']
def _error(status_code):
webnotes.errprint(webnotes.utils.get_traceback())
webnotes._response.status_code = status_code
if webnotes.request_method == "POST":
webnotes.conn.rollback()

if cmd!='login':
# login executed in webnotes.auth
if webnotes.request_method == "POST":
webnotes.conn.begin()
status_codes = {
webnotes.PermissionError: 403,
webnotes.AuthenticationError: 401,
webnotes.DoesNotExistError: 404,
webnotes.SessionStopped: 503,
webnotes.OutgoingEmailError: 501
}
try:
execute_cmd(cmd)
except webnotes.ValidationError, e:
webnotes.errprint(webnotes.utils.get_traceback())
if webnotes.request_method == "POST":
webnotes.conn.rollback()
except webnotes.PermissionError, e:
webnotes.errprint(webnotes.utils.get_traceback())
webnotes._response.status_code = 403
if webnotes.request_method == "POST":
webnotes.conn.rollback()
except:
webnotes.errprint(webnotes.utils.get_traceback())
if webnotes.request_method == "POST":
webnotes.conn and webnotes.conn.rollback()

if webnotes.request_method == "POST" and webnotes.conn:
webnotes.conn.commit()
except Exception, e:
_error(status_codes.get(e.__class__, 500))
else:
if webnotes.request_method == "POST" and webnotes.conn:
webnotes.conn.commit()
print_response()



+ 6
- 5
webnotes/public/js/wn/request.js ファイルの表示

@@ -58,18 +58,17 @@ wn.request.call = function(opts) {
type: 'POST',
dataType: opts.dataType || 'json',
statusCode: {
404: function(xhr) {
msgprint("Not Found");
},
403: function(xhr) {
wn.request.cleanup(opts, {});
msgprint("Not Permitted");
opts.error && opts.error(xhr)
},
200: function(data, xhr) {
wn.request.cleanup(opts, data);
opts.success && opts.success(data, xhr.responseText);
}
},
fail: function(xhr, textStatus) {
wn.request.cleanup(opts, {});
opts.error && opts.error(xhr)
},
async: opts.async
@@ -101,7 +100,9 @@ wn.request.call = function(opts) {
})
}
return $.ajax(ajax_args);
return $.ajax(ajax_args).always(function(data) {
wn.request.cleanup(opts, data);
});
}

// call execute serverside request


+ 19
- 15
webnotes/templates/includes/login.js ファイルの表示

@@ -62,23 +62,27 @@ login.do_login = function(){
url: "/",
data: args,
dataType: "json",
success: function(data) {
$("#login-spinner").toggle(false);
$('#login_btn').prop("disabled", false);
if(data.message=="Logged In") {
window.location.href = "app.html";
} else if(data.message=="No App") {
if(localStorage) {
var last_visited = localStorage.getItem("last_visited") || "index";
localStorage.removeItem("last_visited");
window.location.href = last_visited;
} else {
window.location.href = "index";
}
} else {
login.set_message(data.message || data._server_messages);
statusCode: {
200: function(data) {
if(data.message=="Logged In") {
window.location.href = "app.html";
} else if(data.message=="No App") {
if(localStorage) {
var last_visited = localStorage.getItem("last_visited") || "index";
localStorage.removeItem("last_visited");
window.location.href = last_visited;
} else {
window.location.href = "index";
}
}
},
401: function(xhr, data) {
login.set_message("Invalid Login");
}
}
}).always(function(){
$("#login-spinner").toggle(false);
$('#login_btn').prop("disabled", false);
})
return false;


読み込み中…
キャンセル
保存