Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON.parse error #11

Open
titulus opened this issue Apr 5, 2016 · 1 comment
Open

JSON.parse error #11

titulus opened this issue Apr 5, 2016 · 1 comment

Comments

@titulus
Copy link

titulus commented Apr 5, 2016

When odoo server is not working propperly, it can respond anything instaead of data you want.
Like

Internal Server Error

The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.

Instead of json when postgres is down.

Example of code:

try {
  odoo.connect(function (err) {
    if (err) { return console.log('odoo.connect handle error: ',err); }
  });
} catch (err) {
  console.log('odoo.connect error: ',err);
}

Error throwing:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
^

SyntaxError: Unexpected token <
    at Object.parse (native)
    at IncomingMessage.<anonymous> (D:\work\a.kuntsevich\Dropbox\work\vnc-project\vnc-proj\service\node_modules\odoo\lib\index.js:53:23)
    at emitNone (events.js:72:20)
    at IncomingMessage.emit (events.js:166:7)
    at endReadableNT (_stream_readable.js:905:12)
    at nextTickCallbackWith2Args (node.js:474:9)
    at process._tickCallback (node.js:388:17)
[Finished in 0.7s with exit code 1]

It can't be handled with try{} catch{} construction too

But wrapping response = JSON.parse(response); into try{} catch{} can solve this problem:

try {
  response = JSON.parse(response);
} catch (err) {
  return cb(err, null);
}

in res.on('end', ...) will handle the error instead of throwing it:

odoo.connect handle error:  [SyntaxError: Unexpected token <]
@titulus
Copy link
Author

titulus commented Jun 7, 2016

@saidimu where are you?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant