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

Uncaught SyntaxError: Unexpected token a #44

Closed
bmrinal opened this issue Jul 27, 2016 · 5 comments
Closed

Uncaught SyntaxError: Unexpected token a #44

bmrinal opened this issue Jul 27, 2016 · 5 comments
Assignees

Comments

@bmrinal
Copy link

bmrinal commented Jul 27, 2016

[Enter steps to reproduce below:]

  1. ...
  2. ...

Atom Version: 1.8.0
System: Mac OS X 10.11.5
Thrown From: rest-client package, v1.2.0

Stack Trace

Uncaught SyntaxError: Unexpected token a

At file:///Users/mrinal/Downloads/Atom.app/Contents/Resources/app.asar/static/index.html#%7B%22initialPaths%22%3A%5B%22%2FVolumes%2FData%2Fusers%2Fmrinal%2Fprojects%2Fmangoapi%22%5D%2C%22locationsToOpen%22%3A%5B%7B%22pathToOpen%22%3A%22%2FVolumes%2FData%2Fusers%2Fmrinal%2Fprojects%2Fmangoapi%22%2C%22initialLine%22%3Anull%2C%22initialColumn%22%3Anull%7D%5D%2C%22windowInitializationScript%22%3A%22%2FUsers%2Fmrinal%2FDownloads%2FAtom.app%2FContents%2FResources%2Fapp.asar%2Fsrc%2Finitialize-application-window.js%22%2C%22resourcePath%22%3A%22%2FUsers%2Fmrinal%2FDownloads%2FAtom.app%2FContents%2FResources%2Fapp.asar%22%2C%22devMode%22%3Afalse%2C%22safeMode%22%3Afalse%2C%22clearWindowState%22%3Afalse%2C%22appVersion%22%3A%221.8.0%22%2C%22atomHome%22%3A%22%2FUsers%2Fmrinal%2F.atom%22%7D:1

SyntaxError: Unexpected token a
    at Object.parse (native)
    at RestClientView.module.exports.RestClientView.getRequestBody (/Users/mrinal/.atom/packages/rest-client/lib/rest-client-view.coffee:293:27)
    at RestClientView.module.exports.RestClientView.getRequestOptions (/Users/mrinal/.atom/packages/rest-client/lib/rest-client-view.coffee:263:14)
    at RestClientView.module.exports.RestClientView.sendRequest (/Users/mrinal/.atom/packages/rest-client/lib/rest-client-view.coffee:238:24)
    at HTMLButtonElement.<anonymous> (/Users/mrinal/.atom/packages/rest-client/lib/rest-client-view.coffee:167:43)
    at space-pen-div.jQuery.event.dispatch (/Users/mrinal/Downloads/Atom.app/Contents/Resources/app.asar/node_modules/jquery/dist/jquery.js:4435:9)
    at space-pen-div.elemData.handle (/Users/mrinal/Downloads/Atom.app/Contents/Resources/app.asar/node_modules/jquery/dist/jquery.js:4121:28)

Commands

     -6:04.4.0 core:cut (textarea.field.rest-client-headers)
     -6:02.6.0 core:select-all (textarea.field.rest-client-payload)
     -6:02.0 core:paste (textarea.field.rest-client-payload)
  2x -5:51.7.0 core:cancel (textarea.field.rest-client-payload)
     -5:05.3.0 core:select-all (textarea.field.rest-client-payload)
     -5:04.3.0 core:cut (textarea.field.rest-client-payload)
     -4:51.3.0 rest-client:show (atom-text-editor.editor.power-mode.is-focused)
     -4:42.1.0 core:paste (textarea.field.rest-client-payload)
  2x -2:37.3.0 core:save (textarea.field.rest-client-payload)
     -2:32.1.0 core:select-all (textarea.field.rest-client-payload)
  2x -2:31.7.0 core:copy (textarea.field.rest-client-payload)
     -2:24.3.0 rest-client:show (atom-text-editor.editor.power-mode.is-focused)
     -2:19.4.0 core:select-all (textarea.field.rest-client-headers)
     -2:16.1.0 core:paste (textarea.field.rest-client-payload)
     -1:57.5.0 settings-view:open (div.rest-client.native-key-bindings.padded.pane-item)
     -1:15.3.0 core:confirm (atom-text-editor.editor.mini.is-focused)

Config

{
  "core": {
    "themes": [
      "one-light-ui",
      "one-light-syntax"
    ]
  },
  "rest-client": {}
}

Installed Packages

# User
activate-power-mode, v0.7.0
atom-beautify, v0.29.10
atom-formatter-jsbeautify, v1.1.2
formatter-jsbeautify, v1.0.2
rest-client, v1.2.0

# Dev
No dev packages
@ddavison
Copy link
Owner

ddavison commented Jul 27, 2016

something like this would happen when you have the "application/json" mime type selected, but your API that you are requesting is returning borked JSON.

look into the api you are polling from.. take the result and put it through http://jsonlint.com. you'll see that it's malformed JSON.

@bmrinal
Copy link
Author

bmrinal commented Jul 27, 2016

no the problem is actually in the payload parsing. If the payload is not a valid JSON, it breaks and gives me this error. API is fine. API is not even called. It breaks before that.

Can't we can have a graceful warning saying that the payload is invalid or something instead of this long error.

@ddavison
Copy link
Owner

could you tell me the method you are using? I tried doing a POST request using { "some inv"alid json } and didn't get an error. how exactly are you sending the request

@bmrinal
Copy link
Author

bmrinal commented Jul 28, 2016

method i am using is "application/json". My payload was {somekey:"somevalue"}. So the quotes were missing around the keys. As soon as I got the quotes wrapped, it worked.

There is one more issue. Saved searches just disappear next day! Maybe I should open another issue for the same.

@javaguirre
Copy link
Contributor

We should return a human message if the json is not correct in the response

@javaguirre javaguirre self-assigned this Aug 29, 2016
javaguirre added a commit that referenced this issue Aug 29, 2016
Fix wrong json payload error, close #44
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

3 participants