Merge pull request #172 from JoahG/403-handling

Adds 403/404 Handling
This commit is contained in:
zhangyaning
2016-02-17 15:10:25 +08:00
3 changed files with 63 additions and 10 deletions

View File

@@ -87,6 +87,7 @@ var github_user_starred_resume = function(username, page) {
var repos = [];
var page = (page ? page : 1);
var url = 'https://api.github.com/users/' + username + '/starred?page=' + page;
var errorMsg;
$.ajax({
url: url,
@@ -94,9 +95,20 @@ var github_user_starred_resume = function(username, page) {
dataType: 'json',
success: function(data) {
repos = data;
},
error: function(e) {
if (e.status == 403) {
errorMsg = 'api_limit'
} else if (e.status == 404) {
errorMsg = 'not_found'
}
}
});
if (errorMsg === 'api_limit' || errorMsg === 'not_found') {
return errorMsg;
}
$.each(repos, function(i, repo) {
if (repo.full_name == "resume/resume.github.com") {
star = true;
@@ -118,17 +130,38 @@ var github_user_starred_resume = function(username, page) {
var run = function() {
var itemCount = 0,
maxItems = 5,
maxLanguages = 9;
maxLanguages = 9,
starred = github_user_starred_resume(username);
if (! github_user_starred_resume(username)) {
$.ajax({
url: 'views/opt_out.html',
dataType: 'html',
success: function(data) {
var template = data;
$('#resume').html(data);
}
});
if (! starred || starred === 'api_limit' || starred === 'not_found') {
if (starred === 'api_limit') {
$.ajax({
url: 'views/api_limit.html',
dataType: 'html',
success: function(data) {
var template = data;
$('#resume').html(data);
}
});
} else if (starred === 'not_found') {
$.ajax({
url: 'views/not_found.html',
dataType: 'html',
success: function(data) {
var template = data;
$('#resume').html(data);
}
});
} else {
$.ajax({
url: 'views/opt_out.html',
dataType: 'html',
success: function(data) {
var template = data;
$('#resume').html(data);
}
});
}
return;
}

10
views/api_limit.html Normal file
View File

@@ -0,0 +1,10 @@
<div id="doc" class="yui-t7">
<div id="hd" role="banner"><h1>API Limit Reached</h1></div>
<div id="bd" role="main">
<div class="yui-g">
<p>The API rate limit has been exceeded for your IP address. Please try again later.</p>
</div>
</div>
<div id="ft" role="contentinfo"></div>
</div>

10
views/not_found.html Normal file
View File

@@ -0,0 +1,10 @@
<div id="doc" class="yui-t7">
<div id="hd" role="banner"><h1>User Not Found</h1></div>
<div id="bd" role="main">
<div class="yui-g">
<p>The user you requested was not found. Please check your spelling and try again.</p>
</div>
</div>
<div id="ft" role="contentinfo"></div>
</div>