[Kimchi-devel] [Wok] Doubts about JS on login page.

Ramon Medeiros ramonn at linux.vnet.ibm.com
Mon Jan 16 11:38:07 UTC 2017


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.

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"
}

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 at br.ibm.com

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ovirt.org/pipermail/kimchi-devel/attachments/20170116/3bb2a561/attachment.html>


More information about the Kimchi-devel mailing list