Author Topic: "Server Error! (OK)" due to "SyntaxError: Unexpected token <"  (Read 7419 times)

Offline dim-0

  • Newbie
  • *
  • Posts: 6
"Server Error! (OK)" due to "SyntaxError: Unexpected token <"
« on: December 20, 2013, 05:27:18 AM »
Hi there,

I recently installed a fresh roundcube package (first version 0.7.1 from the Ubuntu sources, later version 0.9.5 from Nicolas Delvaux's backports) on my server.

Logging in works perfectly. However, whatever I do, I get the error message "Server Error! (OK)" which prevents me from navigating within roundcube - I cannot even log off nor can I open the settings or anything else. The mails won't show up either.

Logs (Roundcube, Dovecot, Nginx) don't show anything of interest. IMAP works just as expected.

I traced down the error message  and found out, the "OK" is just the translation of the response code "200". So this doesn't seem to be related to the overall connectivity.
Next I tried to debug this within Chromium's JavaScript console. I put a break point at every http_error execution and it stoppend in line 4615: rcmail.http_error(o, status, err, lock)
The err.message variable holds the value "Unexpected token <".
The err.stack holds "SyntaxError: Unexpected token <
at Object.parse(native)
at bF.extend.parseJSON(https://mail.xyz.org/program/js/jquery.min.js?s=1340930259:16:5340)
at F (https://mail.xyz.org/program/js/jquery.min.js?s=1340930259:23:45040)
at bF (https://mail.xyz.org/program/js/jquery.min.js?s=1340930259:23:40941)
at XMLHttpRequest.bv(https://mail.xyz.org/program/js/jquery.min.js?s=1340930259:23:48300)"

To me it seems like my server answers with a full HTML page (beginning with "<!DOCTYPE ..." which could cause the problem) and JSON is not able to parse this.

Do you know what goes wrong here? Is the response supposed to be like this?

Thanks a lot already for your support. This makes me go crazy already...

Cheers!
« Last Edit: December 20, 2013, 05:31:30 AM by dim-0 »

Offline SKaero

  • Administrator
  • Hero Member
  • *****
  • Posts: 5,600
    • http://SKaero.com/
Re: "Server Error! (OK)" due to "SyntaxError: Unexpected token <"
« Reply #1 on: December 20, 2013, 02:11:31 PM »
Make sure there isn't white space at the top of any of the configuration files.

Offline dim-0

  • Newbie
  • *
  • Posts: 6
Re: "Server Error! (OK)" due to "SyntaxError: Unexpected token <"
« Reply #2 on: December 21, 2013, 02:10:22 PM »
Nope, that doesn't seem to be the issue.  There is no config file with neither whitespace nor empty line at the top. There isn't even any whitespace at the beginning of each line.

The error gets thrown at this code part in file app.js:
    this.http_request = function(action, query, lock) {
        var url = this.url(action, query);
        var result = this.triggerEvent("request" + action, query);
        if (result !== undefined) {
            if (result === false) {
                return false
            } else {
                query = result
            }
        }
        url += "&_remote=1";
        this.log("HTTP GET: " + url);
        return $.ajax({type: "GET",url: url,data: {_unlock: (lock ? lock : 0)},dataType: "json",success: function(data) {
                ref.http_response(data)
            },error: function(o, status, err) {
                rcmail.http_error(o, status, err, lock)
            }})
    };

If I got it right, the response coming back from the server even seems to be the login page.

Thank you so much for your support!
« Last Edit: December 21, 2013, 02:18:22 PM by dim-0 »

Offline ABerglund

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 673
Re: "Server Error! (OK)" due to "SyntaxError: Unexpected token <"
« Reply #3 on: December 21, 2013, 02:37:20 PM »
First thing I'd do is ditch the backport version and install from tarball. Roundcube is ridiculously simple to install, just expand from the tarball, chown/chmod the temp and logs folders and edit config files. That's it. I hear of too many problems from re-packaged installs by various distros.
Arne Berglund
SysAdmin, Internet Services
Lane Education Service District
Eugene, OR, USA

Offline dim-0

  • Newbie
  • *
  • Posts: 6
Re: "Server Error! (OK)" due to "SyntaxError: Unexpected token <"
« Reply #4 on: December 22, 2013, 09:31:00 AM »
Alright, did that, too, with latest stable version. Doesn't change anything regarding this error.
:(

Whatever request is sent to the server, it seems like the server responds with the login page.
JSON then complains because it cannot interpret the HTML tags...

Offline ABerglund

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 673
Re: "Server Error! (OK)" due to "SyntaxError: Unexpected token <"
« Reply #5 on: December 22, 2013, 03:33:51 PM »
OK, please provide the config entries relating to all things IMAP. You can change the hostname if you wish.

Also, is Roundcube installed on the same server as Dovecot? Or a separate server?
Arne Berglund
SysAdmin, Internet Services
Lane Education Service District
Eugene, OR, USA

Offline John124

  • Newbie
  • *
  • Posts: 1
Re: "Server Error! (OK)" due to "SyntaxError: Unexpected token <"
« Reply #6 on: December 22, 2013, 04:24:49 PM »
First thing I'd do is ditch the backport version and install from tarball. Roundcube is ridiculously simple to install, just expand from the tarball, chown/chmod the temp and logs folders and edit config files. That's it. I hear of too many problems from re-packaged installs by various distros. There are also websites that show this simple process.

Tried this but didn't work.  Any other suggestions?  Thanks.
« Last Edit: December 31, 2013, 05:01:14 PM by John124 »

Offline dim-0

  • Newbie
  • *
  • Posts: 6
Re: "Server Error! (OK)" due to "SyntaxError: Unexpected token <"
« Reply #7 on: December 22, 2013, 05:21:41 PM »
$rcmail_config['default_host'] = 'localhost';
$rcmail_config['default_port'] = 143;
$rcmail_config['imap_auth_type'] = null;
$rcmail_config['imap_ns_personal'] = null;
$rcmail_config['imap_ns_other'] = null;
$rcmail_config['imap_ns_shared'] = null;
$rcmail_config['imap_force_caps'] = false;
$rcmail_config['imap_force_lsub'] = false;
$rcmail_config['imap_force_ns'] = false;
$rcmail_config['imap_timeout'] = 0;
$rcmail_config['imap_auth_cid'] = null;
$rcmail_config['imap_auth_pw'] = null;
$rcmail_config['imap_cache'] = null;
$rcmail_config['messages_cache'] = false;

Roundcube, Dovecot and Nginx run ob the same server. Logins running via dovecot are running smoothly.

Thanks!

Offline dim-0

  • Newbie
  • *
  • Posts: 6
Re: "Server Error! (OK)" due to "SyntaxError: Unexpected token <"
« Reply #8 on: December 26, 2013, 09:01:22 PM »
Hey, found out today:

Whenever I get the error displayed in the browser, these lines are added to the SQL log:
[27-Dec-2013 02:32:19 +0100]: [1] SET NAMES 'utf8';
[27-Dec-2013 02:32:19 +0100]: [2] SELECT vars, ip, changed FROM session WHERE sess_id = 'qs7vta7sbbjlbuf72aajq0rbf7';
[27-Dec-2013 02:32:19 +0100]: [3] SELECT * FROM users WHERE user_id = '1';
[27-Dec-2013 02:32:21 +0100]: [4] SELECT * FROM identities WHERE del <> 1 AND user_id = '1' ORDER BY "standard" DESC, name ASC, identity_id ASC;
[27-Dec-2013 02:32:21 +0100]: [5] SELECT vars, ip, changed FROM session WHERE sess_id = 'qs7vta7sbbjlbuf72aajq0rbf7';

However, if I log in to the roundcube database (PostgreSQL) as the roundcube user, all of those queries return valid results.

So, current state of information:
1. Browser submits a query
2. Server runs the select statements
3. JSON response from server is an HTML page (login) which of course cannot be parsed
4. Screen shows the corresponding error

The problem must lie somewhere between steps 2 and 3.
I think we can be sure that the PHP functions respond with valid information, as it seems this problem doesn't occure too often (at least I haven't found any similar posts on the internet).
Then there are 2 other components left:
- PHP5-FPM which I use as the application server
--> logs are empty
- Nginx as the web server
--> logs are empty

Grrr...!

Offline dim-0

  • Newbie
  • *
  • Posts: 6
Re: "Server Error! (OK)" due to "SyntaxError: Unexpected token <"
« Reply #9 on: December 27, 2013, 06:00:45 PM »
Alright, got it solved.
The problem was located in my nginx configuration. The locations got screwed up, as the request URL was not resolved to PHP-FPM for the JSON requests (by my mistake).

Thank you everybody for your support!