Skip to content

Commit

Permalink
issue #9 handle repo 404
Browse files Browse the repository at this point in the history
- invoke onRepositoryError event on non-200 status
  • Loading branch information
rviscomi committed Oct 12, 2012
1 parent 1fc0b9b commit 67b1b62
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -62,6 +62,8 @@ Event handlers are defined by including functions keyed by the respective event

* **onRepositoryLoaded** Fired after successfully loading repository info from the GitHub API.
* `data` The data object returned by GitHub.
* **onRepositoryError** Fired after unsuccessfully loading repository info from the GitHub API.
* `message` The error message returned by GitHub.
* **onCacheLoaded** Fired after successfully loading the JSON cache file.
* **onStargazersUpdated** Fired after processing a chunk of at most 100 repository stargazers.
* `num_stargazers` The number of stargazers processed so far.
Expand Down
16 changes: 11 additions & 5 deletions red-dwarf.js
@@ -1,11 +1,11 @@
/**!
* red dwarf v1.0.4
* red dwarf v1.0.5
* https://github.com/rviscomi/red-dwarf
*
* Copyright 2012 Rick Viscomi
* Released under the MIT License.
*
* Date: October 5, 2012
* Date: October 12, 2012
*/

(function () {
Expand Down Expand Up @@ -49,6 +49,7 @@
}

/* Event hooks. */
this.onRepositoryError = options.onRepositoryError || function () {};
this.onRepositoryLoaded = options.onRepositoryLoaded || function () {};
this.onCacheLoaded = options.onCacheLoaded || function () {};
this.onStargazersUpdated = options.onStargazersUpdated || function () {};
Expand Down Expand Up @@ -134,9 +135,14 @@
this.repository,
dataType: 'jsonp',
success: function (data) {
that.num_stargazers = data.data.watchers; // TODO data.stargazers?

that.onRepositoryLoaded(data.data);
if (data.meta.status === 200) {
that.num_stargazers = data.data.watchers; // TODO data.stargazers?

that.onRepositoryLoaded(data.data);
}
else {
that.onRepositoryError(data.data.message);
}
},
complete: onComplete
});
Expand Down

0 comments on commit 67b1b62

Please sign in to comment.