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

Quota message #12

Merged
merged 1 commit into from
Dec 17, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions js/youtube-geofind-v4.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ const geofind = (function() {
}).fail(function(err) {
elements[channel.id].progress.setBg("bg-danger");

internal.displayMessage("alert-warning", JSON.stringify(err));
internal.displayError("alert-warning", err);

console.error(err);
})
Expand Down Expand Up @@ -526,7 +526,7 @@ const geofind = (function() {

elements.loadingDiv.fadeOut(defaults.animationMs);

internal.displayMessage("alert-warning", JSON.stringify(err));
internal.displayError("alert-warning", err);

console.error(err);
});
Expand Down Expand Up @@ -606,6 +606,25 @@ const geofind = (function() {
return request;
},

displayError: function (type, err) {
if (err.responseJSON
&& err.responseJSON.error
&& err.responseJSON.error.errors
&& err.responseJSON.error.errors[0]) {
const error = err.responseJSON.error.errors[0];
if (error.reason === "quotaExceeded") {
const html = "<strong>Quota Exceeded</strong> " +
"The daily API quota of 1,000,000 units has been reached for this application. " +
"This quota resets at midnight Pacific Time (PT) as per the Google Developers Console. " +
"See more detail here with <a target='_blank' href='https://github.com/mattwright324/youtube-geofind/issues/11'>issue #5</a>.";

this.displayMessage('alert-warning', html);
} else {
this.displayMessage('alert-warning', JSON.stringify(err));
}
}
},

displayMessage: function(type, message) {
const html =
"<div class='alert alert-dismissable fade show "+type+"' role='alert'>" +
Expand Down Expand Up @@ -1062,7 +1081,7 @@ const geofind = (function() {
}).fail(function(err) {
console.error(err);

internal.displayMessage("alert-warning", JSON.stringify(err));
internal.displayError("alert-warning", err);

elements.loadingDiv.fadeOut(1000);
});
Expand All @@ -1080,7 +1099,7 @@ const geofind = (function() {
).done(function(res) {
callback(res);
}).fail(function(err) {
internal.displayMessage("alert-warning", JSON.stringify(err));
internal.displayError("alert-warning", err);

console.error(err);
});
Expand Down