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

Invalid Error Response #282

Open
aklgupta opened this issue May 9, 2019 · 0 comments
Open

Invalid Error Response #282

aklgupta opened this issue May 9, 2019 · 0 comments

Comments

@aklgupta
Copy link

aklgupta commented May 9, 2019

I am using octokat v0.10.0,
While trying to handle bad login request, I noticed that the response in case of an error is invalid.
I was unable to use it as a JSON. The object type is object, however, the object has no keys.
Parsing it using JSON.parse thrown error as well.

The response I receive is as follows:

Error: {
  "message": "Bad credentials",
  "documentation_url": "https://developer.github.com/v3"
}
 GET https://api.github.com/repos/f/f Status: 401
    at eval (requester.js:225)

Here's my code snippet

console.log(username);
console.log(password);
console.log(reponame);

var octo = new Octokat({
	username: username,
	password: password,
});
var repo = octo.repos(username, reponame);

repo.fetch()
.then((info) => {
	// do work
})
.catch((err) => {
	console.log("error");
	console.log(err);
	console.log(typeof(err));
	console.log(err.message);
	console.log(typeof(err.message));
	// JSON.parse(err);
	JSON.parse(err.message);
	this.status = 'failure';
});

Output of the above code is:

user  // Changed intentionally
pass  // Changed intentionally
repo  // Changed intentionally

GET https://api.github.com/repos/f/f 401 (Unauthorized)

error

Error: {
  "message": "Bad credentials",
  "documentation_url": "https://developer.github.com/v3"
}
 GET https://api.github.com/repos/f/f Status: 401
    at eval (requester.js:225)

object

{
  "message": "Bad credentials",
  "documentation_url": "https://developer.github.com/v3"
}
 GET https://api.github.com/repos/f/f Status: 401


string

index.js:97 Uncaught (in promise) SyntaxError: Unexpected token G in JSON at position 0
    at JSON.parse (<anonymous>)
    at eval (index.js:97)

How do I parse this error response? Even octo.parse was not helpful

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