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

Handling of unexpected server responses #17

Closed
MJochim opened this issue Jan 18, 2017 · 3 comments
Closed

Handling of unexpected server responses #17

MJochim opened this issue Jan 18, 2017 · 3 comments

Comments

@MJochim
Copy link

MJochim commented Jan 18, 2017

Opening a new issue as a copy of my comment on #11. Unexpected server responses (such as a 401/Not authorized; or if the specified server is not a Gitlab instance) may lead to obscure error messages.

Steps to reproduce

  1. git clone, npm i, cp sample_settings.json settings.json
  2. Replace the value of gitlab.url in settings.json (use e.g. https://gitlab.lrz.de/ or http://www.google.de/)
  3. node index.js

Result

If you use an actual gitlab instance in step 2, you get the message described in #11 (“Unexpected token o in JSON at position 1”).
If you use some other URL (e.g. Google), you get a different message.

Comment

This needs fixing in the gitlab package and has actually been documented at jdalrymple/gitbeaker#149.

However some changes in this codebase might also be in order. Try making the change I suggested upstream, repeat the steps to reproduce and you will end up with another error:

TypeError: projects.sort is not a function

Something like Array.isArray(projects) inside the callback function on line 16 might do the trick.

@MJochim
Copy link
Author

MJochim commented Jan 18, 2017

Addendum: After applying the suggested patch to the gitlab package, if I choose google.de as my gitlab.url, there is no error message. The projects variable is an empty array, which the code can handle. This at least is no crash :-).

It would of course be great if we could determine whether the specified server is really a Gitlab server and if not, warn the user (they have leaked their Gitlab access token to a foreign server, after all). But I don’t know if that is possible or feasible.

@spruce
Copy link
Member

spruce commented Jan 25, 2017

What would you recommend to do? maybe manually request the gitlab url and check whether gitlab returns some header.

As I see it currently I will wait for a change in the upstream module. Otherwise I can't do anything. IMO.

@spruce
Copy link
Member

spruce commented Mar 24, 2018

As of now the error is printed on the console which should contain the body where this should get clearer. I gonna close this because I think it is now stated clearly enough. Reopen if you think otherwise. 👍

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

No branches or pull requests

2 participants