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

Error Body not parsing properly for cherry pick #499

Closed
sdc224 opened this issue Nov 23, 2019 · 29 comments
Closed

Error Body not parsing properly for cherry pick #499

sdc224 opened this issue Nov 23, 2019 · 29 comments
Labels

Comments

@sdc224
Copy link

sdc224 commented Nov 23, 2019

Hi,

I am using this node dependency to create a VSCode extension. My extension supports Cherry Picking a commit just like Gitlab way(I mean start a new Merge Request while cherry picking). But when I am trying to use the cherryPick function like

try {
      const res2 = await api.Commits.cherryPick(8916, <sha>, `cherry-pick-${commit.short_id}`);
      console.log(res2); 
 } catch (error) {
      console.log(error);
 }

I am getting this error

FetchError: invalid json response body at https://<Git URL>/api/v4/projects/8916/repository/commits/<sha>/cherry_pick reason: Unexpected token < in JSON at position 0
	at d:\HighRadius\Extensions\Typescript Extensions\testing-typescript\node_modules\node-fetch\lib\index.js:272:32
	at processTicksAndRejections (internal/process/task_queues.js:89:5)

Note:

  1. I am using gitlab inside company(I mean company specific gitlab domain)
  2. I am replacing the with my company's git domain
  3. Replace with a big hash value of a commit

Already I have tried MergeRequests, Commits, they are working fine.

@jdalrymple jdalrymple added the Bug label Nov 23, 2019
@jdalrymple
Copy link
Owner

Hmm, not sure, ill give it a look :)

@sdc224
Copy link
Author

sdc224 commented Nov 23, 2019

Thank you for your response, please let me know whether it is an issue from my side or repository side

@sdc224
Copy link
Author

sdc224 commented Nov 25, 2019

Guys any update regarding this?

@jetersen
Copy link
Contributor

Would if you could debug further. By looking at way it is trying to parse.
Or attempt to make similar request from something like post man

@sdc224
Copy link
Author

sdc224 commented Nov 26, 2019

Ya I am getting the response as an HTML body in Postman, it is showing that

"Sorry, we cannot cherry-pick this commit automatically. This commit may already have been
cherry-picked, or a more recent commit may have updated some of its content."

But as per the API docs, it should throw the same error message in JS as well

@jdalrymple
Copy link
Owner

So the error is being eaten up somewhere. hmm

@jdalrymple
Copy link
Owner

Could be a few things, I'm guessing the response content-type is json but the actual content is an html page. This would explain the < error, and is similar to what is explained here https://stackoverflow.com/questions/56178321/invalid-json-response-body-error-with-express-node-fetch-using-formdata

could you check the content-type you are getting from the postman request?

@sdc224
Copy link
Author

sdc224 commented Nov 27, 2019

Ya the content type is HTML in Postman

@jdalrymple
Copy link
Owner

jdalrymple commented Nov 27, 2019

@sdc224 So in the headers, it says the content-type is one of the below:

Content-Type: text/html; charset=UTF-8
Content-Type: multipart/form-data; boundary=something

?

I have a strong feeling it still says "application/json"

@sdc224
Copy link
Author

sdc224 commented Nov 27, 2019

Ya @jdalrymple , the headers showing this in response(In Postman)

Content-Type: text/html; charset=UTF-8

One more thing, for all type of errors, it is showing the same in node-gitlab error

FetchError: invalid json response body at https://<Git URL>/api/v4/projects/8916/repository/commits/<sha>/cherry_pick reason: Unexpected token < in JSON at position 0
	at d:\HighRadius\Extensions\Typescript Extensions\testing-typescript\node_modules\node-fetch\lib\index.js:272:32
	at processTicksAndRejections (internal/process/task_queues.js:89:5)

@jdalrymple
Copy link
Owner

Hmm, not really sure then, since the default content-type handler is:

default: {
      const text = await response.text();

      return text || '';
    }

Ill try and recreate it this weekend and see if i can trace the correct source of the error. I'm guessing its within the processBody function.
which should handle the html content type just fine.

@sdc224
Copy link
Author

sdc224 commented Nov 27, 2019

Sure man, thanks for looking into it

@sdc224
Copy link
Author

sdc224 commented Nov 30, 2019

Guys got any solution?

@jdalrymple
Copy link
Owner

Not yet, still writing up a good test to recreate this

@jdalrymple
Copy link
Owner

I was able to recreate your test case, but it seems to error out properly, not with the one you outlined above (json parsing error).

Could you provide some more information about your setup? The library version you are using? Or even a test repository with the error recreated.

@sdc224
Copy link
Author

sdc224 commented Nov 30, 2019

Sir need to first clear one thing that I am using git in VPN, which means I am using this library for calling git API of our organisation created in gitlab. So maybe that might creating some issue
I will try to replicate my issue in a local gitlab account, if the issue is still persist, I will reply back
Please look into that VPN part, maybe you guys can figure out something

@sdc224
Copy link
Author

sdc224 commented Dec 1, 2019

I am using 12.0.0 version of gitlab.

For any kind of error message, it is showing the same as above(Unexpected < )

@jdalrymple
Copy link
Owner

@sdc224 Were you able to test with your local gitlab account? I cant do much about your VPN setup lol. Might have to do with your security settings. Have you checked if its has to do with certificates? maybe try the 12.1.1 beta and setting rejectUnauthorized:false

@sdc224
Copy link
Author

sdc224 commented Dec 5, 2019

@jdalrymple Sorry for late reply man
Actually while using gitlab as host(from my personal account), it is perfectly working.
The error message is also coming as expected.
But still it is not working for my company's host.
Will try whatever you have told, and update here. Is there anything that needs to be configured from our side, so that the error message will appear properly?

@sdc224
Copy link
Author

sdc224 commented Dec 5, 2019

Sorry but I am not getting your steps, can you please elaborate a little?

@sdc224
Copy link
Author

sdc224 commented Dec 5, 2019

In Postman, we are getting some HTML pages as response instead of a JSON showing {message: ""}
For my company host
Although the HTML shows the exact problem...404 not found or 403 no access etc.
Is there any tool so that I can parse my error HTML messages as JSON instead of showing "Unexpected <" error?

@sdc224
Copy link
Author

sdc224 commented Dec 5, 2019

One more thing, can anyone tell me the difference between MergeRequests.accept and MergeRequests.approve?

@jdalrymple
Copy link
Owner

@sdc224 If youre getting that response in postman, then the library wont be useful to you. The html page usually comes up when there is a security issue. What is the HTML page that is being returned? Is it the login page?

As for your second question:
accept: https://docs.gitlab.com/ee/api/merge_requests.html#accept-mr
approve: https://docs.gitlab.com/ee/api/merge_request_approvals.html#approve-merge-request

@sdc224
Copy link
Author

sdc224 commented Dec 6, 2019

@jdalrymple Thanks you so much for your answer for the second question.

For the response thing, we are getting an HTML page saying 404 not found. I just want to know is there any provision to pass the HTML and return some good error message in JS?
Please tell us if we need to change something so that the error message would come as a JSON, instead of HTML

@jdalrymple
Copy link
Owner

If we can recreate the error, then yea ill add a way to work around the html thing. As for now, I haven't been able to recreate the html response and while i have seen Not Found Errors, those are handled correctly.

@jdalrymple jdalrymple added question and removed Bug labels Dec 7, 2019
@sdc224
Copy link
Author

sdc224 commented Dec 8, 2019

Sure guys, thank you all for your efforts to help me out in this matter. I will try to solve my problem, if I got any update, then I will inform you all. By the way, please help me if you come to know anything regarding parsing HTML as JSON.

One more question guys, while uisng the Cherry Pick, it is not creating any MR just like we can cherry pick a Merge Request in Gitlab UI. Is there any other API to do that(I know how to do it step by step...creating a new branch, cherry pick into that and MR...I want to know a one step process)

@sdc224 sdc224 closed this as completed Dec 8, 2019
@jdalrymple
Copy link
Owner

@sdc224 I dont think that functionally currently exists in the API :'(

@sdc224
Copy link
Author

sdc224 commented May 22, 2020

Hi guys,

In webpage console I get the exact error code everytime while doing this, only the response contains HTML, that's why I get Unexpected end of JSON

GET https://<Organization GIT URL>/api/v4/projects?per_page=100 403 (Forbidden)

at @gitbreaker/browser/dist/index.js : 16

Is there any way to intercept that error or return it from the library, to help in this kind of scenario?

@jdalrymple
Copy link
Owner

Working on that right now #764 :)

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