<html>
  <head>
    <meta content="text/html; charset=windows-1252"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <br>
    <br>
    <div class="moz-cite-prefix">On 01/16/2017 09:38 AM, Ramon Medeiros
      wrote:<br>
    </div>
    <blockquote
      cite="mid:d0e8c43c-ed9c-26d8-fa6f-cd306c4f268c@linux.vnet.ibm.com"
      type="cite">
      <meta http-equiv="content-type" content="text/html;
        charset=windows-1252">
      <p>Hi,</p>
      <p>i'm doing the issue <a moz-do-not-send="true"
          class="moz-txt-link-freetext"
          href="https://github.com/kimchi-project/wok/issues/147">https://github.com/kimchi-project/wok/issues/147</a>,
        and got a problem to deal with exceptions and Javascript. I got
        this code at src/wok/root.py:<br>
        <br>
               # check for repetly<br>
                l = len(self.failed_logins)<br>
                if l &gt;= 3:<br>
        <br>
                    # verify if timeout is still valid<br>
                    last_try = self.failed_logins[l -1]<br>
                    if time.time() &lt; (last_try["time"] +
        self.fail_timeout):<br>
                        details = e = UnauthorizedError("WOKAUTH0004E",<br>
                                                        {"seconds":
        self.fail_timeout})<br>
                        log_request(code, params, details, method, 403)<br>
                        import pdb;pdb.set_trace()<br>
                        raise cherrypy.HTTPError(403, e.message)<br>
                        return e.message<br>
        <br>
        <br>
        So, it may raise an exception. I want to filter this exception
        at UI. So i got this code:</p>
      <p><br>
      </p>
      <p>        wok.login(settings, function(data) {<br>
                    var query = window.location.search;<br>
                    var next  = /.*next=(.*?)(&amp;|$)/g.exec(query);<br>
        <br>
                    if (next) {<br>
                        var next_url = decodeURIComponent(next[1]);<br>
                    }<br>
                    else {<br>
                        var lastPage = wok.cookie.get('lastPage');<br>
                        var next_url = lastPage ?
        lastPage.replace(/\"/g,'') : "/";<br>
                    }<br>
                    wok.cookie.set('roles',JSON.stringify(data.roles));<br>
                   
window.location.replace(window.location.pathname.replace(/\/+login.html/,
        '') + next_url);<br>
                }, function(jqXHR, textStatus, errorThrown) {<br>
                    if (jqXHR.responseText == "") {<br>
                        $("#messUserPass").hide();<br>
                        $("#missServer").show();<br>
                    } else {<br>
                        $("#missServer").hide();<br>
                        $("#messUserPass").show();<br>
                    }<br>
                    $("#messSession").hide();<br>
                    $("#logging").hide();<br>
                    $("#login").show();<br>
                });<br>
        <br>
        The issue is:<br>
        <br>
        1) If i raise a cherrypy.HTTPError, i got a html error with the
        message i created on the code. Here is an example <a
          moz-do-not-send="true" class="moz-txt-link-freetext"
          href="http://pastebin.com/AjkWwHBz">http://pastebin.com/AjkWwHBz</a>.
        The message is there, but i must parse it.<br>
        <br>
      </p>
    </blockquote>
    <br>
    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.<br>
    You will need to add a specify 403 error handler for your matters.<br>
    <br>
    <blockquote
      cite="mid:d0e8c43c-ed9c-26d8-fa6f-cd306c4f268c@linux.vnet.ibm.com"
      type="cite">
      <p> 2) If i raise a InvalidOperation or other exception from wok,
        i receive a error 500:<br>
      </p>
      <p> {<br>
           "reason":"The server encountered an unexpected condition
        which prevented it from fulfilling the request.",<br>
           "code":"500 Internal Server Error" <br>
        }<br>
      </p>
    </blockquote>
    <br>
    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.<br>
    <br>
    <blockquote
      cite="mid:d0e8c43c-ed9c-26d8-fa6f-cd306c4f268c@linux.vnet.ibm.com"
      type="cite">
      <p> <br>
        I want to receive a json with the error, to make it to parse
        from UI.<br>
        <br>
      </p>
      <pre class="moz-signature" cols="72">-- 

Ramon Nunes Medeiros
Kimchi Developer
Linux Technology Center Brazil
IBM Systems &amp; Technology Group
Phone : +55 19 2132 7878
<a moz-do-not-send="true" class="moz-txt-link-abbreviated" href="mailto:ramonn@br.ibm.com">ramonn@br.ibm.com</a> </pre>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
Kimchi-devel mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Kimchi-devel@ovirt.org">Kimchi-devel@ovirt.org</a>
<a class="moz-txt-link-freetext" href="http://lists.ovirt.org/mailman/listinfo/kimchi-devel">http://lists.ovirt.org/mailman/listinfo/kimchi-devel</a>
</pre>
    </blockquote>
    <br>
  </body>
</html>