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

Cannot display the reponse if it cannot format it #14

Closed
StephD opened this issue Jul 12, 2016 · 21 comments
Closed

Cannot display the reponse if it cannot format it #14

StephD opened this issue Jul 12, 2016 · 21 comments
Labels

Comments

@StephD
Copy link

StephD commented Jul 12, 2016

  • VSCode Version: 1.3
  • OS Version: Win 7

When the response contain element that cannot be parsed (Php error as exemple), it display the last preview or display an error message : "Unable to open '\response-preview': Unexpected token <."
It would be great to display raw data to be able to read the error.

Cheers

@Huachao Huachao added the bug label Jul 12, 2016
@Huachao
Copy link
Owner

Huachao commented Jul 12, 2016

@StephD, could you please the error sample in more details, is the '<' in response header, or body?

@bogdan-d
Copy link

I get this error too, but i'm not sure about the exact circumstances.
VSCode: 1.3.1
OS: Win 7

Here is the error from the console:

shell.ts:416 data.replace is not a function: TypeError: data.replace is not a function
at Function.HttpResponseTextDocumentContentProvider.escase (C:\Users\user1.vscode\extensions\humao.rest-client-0.5.3\out\src\views\httpResponseTextDocumentContentProvider.js:48:21)
at Function.HttpResponseTextDocumentContentProvider.formatHeaders (C:\Users\user1.vscode\extensions\humao.rest-client-0.5.3\out\src\views\httpResponseTextDocumentContentProvider.js:29:69)
at HttpResponseTextDocumentContentProvider.provideTextDocumentContent (C:\Users\user1.vscode\extensions\humao.rest-client-0.5.3\out\src\views\httpResponseTextDocumentContentProvider.js:12:699)
at c:\Program Files (x86)\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:10:22159
at c:\Program Files (x86)\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:7:441
at new n.Class.derive._oncancel (c:\Program Files (x86)\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:5:16489)
at Object.l [as asWinJsPromise](c:Program Files %28x86%29Microsoft VS CoderesourcesappoutvsworkbenchnodeextensionHostProcess.js:7:406)
at e.$provideTextDocumentContent (c:\Program Files (x86)\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:10:22123)
at c:\Program Files (x86)\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:10:21758
at e.invoke (c:\Program Files (x86)\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:6:23783)
at e.fire (c:\Program Files (x86)\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:6:25565)
at HttpResponseTextDocumentContentProvider.update (C:\Users\user1.vscode\extensions\humao.rest-client-0.5.3\out\src\views\httpResponseTextDocumentContentProvider.js:23:27)
at C:\Users\user1.vscode\extensions\humao.rest-client-0.5.3\out\src\controllers\requestController.js:48:41
at process._tickCallback (internal/process/next_tick.js:103:7)e.onUnexpectedError @ shell.ts:416(anonymous function) @ shell.ts:318e.onUnexpectedError @ errors.ts:73u @ errors.ts:88e.onUnexpectedExtHostError @ mainThreadErrors.ts:12e.handle @ abstractThreadService.ts:34s @ ipcRemoteCom.ts:269f @ ipcRemoteCom.ts:226_combinedTickCallback @ internal/process/next_tick.js:67_tickCallback @ internal/process/next_tick.js:98

@Huachao
Copy link
Owner

Huachao commented Jul 13, 2016

@lypscan it's very strange that string.replace is not a function, can you reproduce this? And could you please provide the request so that I can verify it. 😄

@bogdan-d
Copy link

I made a gif with the bug:

rest-bug

@Huachao
Copy link
Owner

Huachao commented Jul 13, 2016

@lypscan, I can't view your image

@bogdan-d
Copy link

Steps to reproduce:

  1. save a file with the rest extension (test.rest)
  2. do a GET http://example.com HTTP/1.1
  3. close the response-view pane
  4. now change the domain to google.com (GET http://google.com HTTP/1.1)
  5. this is when i receive the error in the console and the response-view pane pops up with the response data of the previous request (from example.com)

@StephD
Copy link
Author

StephD commented Jul 13, 2016

VSCode: 1.3.1
OS: Win 7

I can view it. But it's from a different source for me.
Now I got another error :
Unable to open '\response-preview': data.replace is not a function.
Here is the answer I get into a browser (as RAW).


Notice: Undefined variable: params in C:\var\www******.php on line 58

{"error":"Nothing has been found"}

This is this tag '
' that made the previous error => Unexpected token <.

lypscan, it display the previous data because it can't display the new one (is there a cache?).
If I close VSC, open it, write "GET http://google.com HTTP/1.1" into a new file and run the command, I get the error :
Unable to open '\response-preview': data.replace is not a function.
2016-07-13 09_10_52- untitled-1 - gateway - visual studio code

I just copy the url into the browser and this is 2 picture from firefox developer that have a better display. Chrome only display the raw message.
2016-07-13 09_07_28-http___gateway local cine intra_rest_bypass_auth yes method getcrmsrbyid sr_id 3
2016-07-13 09_07_43-http___gateway local cine intra_rest_bypass_auth yes method getcrmsrbyid sr_id 3

@bogdan-d
Copy link

@Huachao, this bug was not present before the updates (of VSCode 1.3.1 and REST-Client 0.5.3)

@Huachao
Copy link
Owner

Huachao commented Jul 13, 2016

@StephD @lypscan I think this maybe related to the change in v0.5.3, that I will call escape method for each response header value. And I can repro it in my local, I will look into it now.

@Huachao
Copy link
Owner

Huachao commented Jul 13, 2016

@StephD @lypscan I have created the new version 0.5.4, you can update to it and the bug should have be solved. Great thanks to you 😄

@StephD
Copy link
Author

StephD commented Jul 13, 2016

GET http://google.com HTTP/1.1 is working.
My other link is back to the previous error : "Unable to open '\response-preview': Unexpected token <."
The parse shouldn't work but is it possible to see the RAW data?

@bogdan-d
Copy link

@Huachao Yes, for me, this issue is no longer present. Thanks!

@Huachao
Copy link
Owner

Huachao commented Jul 13, 2016

@StephD , could you please provide me the raw request that you issued so that I can debug? Thanks in advance

@StephD
Copy link
Author

StephD commented Jul 13, 2016

Check my previous comment.
Here is the answer I get into a browser (as RAW).


Notice: Undefined variable: params in C:\var\www******.php on line 58

{"error":"Nothing has been found"}

This is this tag '
' that made the previous error => Unexpected token <.

@Huachao
Copy link
Owner

Huachao commented Jul 13, 2016

@StephD. sorry for bothering you to repeat again, and is this the response body, if it is, I can't repro this error since in my code return escape the response body?

@StephD
Copy link
Author

StephD commented Jul 13, 2016

It's alright :)
Yes, this is the response body.
Firefox developer own a json viewer : https://developer.mozilla.org/en-US/docs/Tools/JSON_viewer
I used it to render the rest response body into my rest api.
When I made a mistake into my php code, it's display an error code :


Notice: Undefined variable: params in C:\var\www******.php on line 58

(This is an exemple)

The problem is that the browser and your extension can't render/format the json code because it's not json (But you know that).

Btw, the browser, or other app allow to display the raw/pure data without format it. (as shown into my previous post picture). That allow my to view where come from the error and fix it.

Your extension doesn't allow to view raw data because it force the json format and get an error if not working (I suppose).

May be you should parse the json and if you got an error, just display the data without parsing it.
Here is the PHP function that allow that : http://php.net/manual/en/function.json-last-error.php

I don't know the extension language or VSC code, .... So this is just PHP exemple :(

I hope you understand what I'm trying to say :)

ps : XML format doesn't display VSC error because
tag or "<" token can be parsed into XML.


Notice: Undefined variable: params in C:\var\www******.php on line 58
Nothing has been found

@Huachao
Copy link
Owner

Huachao commented Jul 13, 2016

@StephD, I know your pain now, do you mean that you have a response body with Cotent-Type is application/json, while the result is not real json(due to some bug), so my code failed at json parse. The expected behavior is that if parse failed, just display the original(raw) response body?

@StephD
Copy link
Author

StephD commented Jul 13, 2016

True. I used to call the result the response body (after the CRLF, after the header). Not sure about to standard term.

The content-type is application/json and the result isn't real json because there is an error message.

I would be nice to display the raw data when the parse failed and display an error message to say that the json.parse didn't work).

@Huachao
Copy link
Owner

Huachao commented Jul 13, 2016

@StephD, nice suggestion that add a error/warning message as well when displaying raw response. And I will fix it ASAP

@Huachao
Copy link
Owner

Huachao commented Jul 19, 2016

@StephD you can try latest version 0.5.5 😅

@StephD
Copy link
Author

StephD commented Aug 2, 2016

Awsome, thanks :)

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

No branches or pull requests

3 participants