octokit / octokit.js

The all-batteries-included GitHub SDK for Browsers, Node.js, and Deno.
MIT License
6.94k stars 1.02k forks source link

Is it possible to manually handle error logging? #63

Closed mattiasb closed 10 years ago

mattiasb commented 11 years ago

I'm building a command line interface for node-github and i want to provide my own error handling. Is it possible?

With the following code i expect the output to be only "got an error!" or "got an exception!" (or perhaps a combination thereof):

var GitHubApi = require("github");

var github = new GitHubApi({
    version: "3.0.0"
});

try {
    github.authenticate({
        type: "basic",
        username: "blhaasgdsgh",
        password: "blhaasgdsgh"
    });

    github.repos.fork({
        user: "ajaxorg",
        repo:"node-github"
    }, function(err, res) {
        if(err){
            console.log("got an error!");
        } else {
            console.log("Didn't get an error!");
            console.log(JSON.stringify(res));
        }
    });
} catch (x) {
    console.log("got an exception!");
}

Unfortunately i also get a message like this:

[error] { message: '{"message":"Bad credentials"}', code: 401 } null ajaxorg

that i can't seem to get rid of. Ideas?

mikedeboer commented 11 years ago

Yeah, these are Util.log() calls that I put into index.js rather zealously. I will make an effort to remove those as soon as possible (in other words: only log when in debug mode)

mattiasb commented 11 years ago

That would be awesome! :)

cadorn commented 11 years ago

Don't forget this logging call: https://github.com/ajaxorg/node-github/blob/90dd69495ef16d4b7dca887332cf971741646ccc/api/v3.0.0/index.js#L27

mikedeboer commented 10 years ago

this was done a long time ago, time to close this bug.