
On 01/16/2017 09:38 AM, Ramon Medeiros wrote:
Hi,
i'm doing the issue https://github.com/kimchi-project/wok/issues/147, and got a problem to deal with exceptions and Javascript. I got this code at src/wok/root.py:
# check for repetly l = len(self.failed_logins) if l >= 3:
# verify if timeout is still valid last_try = self.failed_logins[l -1] if time.time() < (last_try["time"] + self.fail_timeout): details = e = UnauthorizedError("WOKAUTH0004E", {"seconds": self.fail_timeout}) log_request(code, params, details, method, 403) import pdb;pdb.set_trace() raise cherrypy.HTTPError(403, e.message) return e.message
So, it may raise an exception. I want to filter this exception at UI. So i got this code:
wok.login(settings, function(data) { var query = window.location.search; var next = /.*next=(.*?)(&|$)/g.exec(query);
if (next) { var next_url = decodeURIComponent(next[1]); } else { var lastPage = wok.cookie.get('lastPage'); var next_url = lastPage ? lastPage.replace(/\"/g,'') : "/"; } wok.cookie.set('roles',JSON.stringify(data.roles)); window.location.replace(window.location.pathname.replace(/\/+login.html/, '') + next_url); }, function(jqXHR, textStatus, errorThrown) { if (jqXHR.responseText == "") { $("#messUserPass").hide(); $("#missServer").show(); } else { $("#missServer").hide(); $("#messUserPass").show(); } $("#messSession").hide(); $("#logging").hide(); $("#login").show(); });
The issue is:
1) If i raise a cherrypy.HTTPError, i got a html error with the message i created on the code. Here is an example http://pastebin.com/AjkWwHBz. The message is there, but i must parse it.
Take a look at root.py lines 47-58. There is set some error handlers according to error code. Probably, the default error handler for 403 is a HTML page set by cherrypy. You will need to add a specify 403 error handler for your matters.
2) If i raise a InvalidOperation or other exception from wok, i receive a error 500:
{ "reason":"The server encountered an unexpected condition which prevented it from fulfilling the request.", "code":"500 Internal Server Error" }
InvalidOperation will raise a 500 error code. The other message is usually used when an exception was not catch by anything. In that case, you should see an traceback in the logs reporting the original exception.
I want to receive a json with the error, to make it to parse from UI.
--
Ramon Nunes Medeiros Kimchi Developer Linux Technology Center Brazil IBM Systems & Technology Group Phone : +55 19 2132 7878 ramonn@br.ibm.com
_______________________________________________ Kimchi-devel mailing list Kimchi-devel@ovirt.org http://lists.ovirt.org/mailman/listinfo/kimchi-devel