Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(558)

Unified Diff: chrome/browser/resources/google_now/cards.js

Issue 22912021: Handling errors from chrome APIs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comments Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/google_now/cards.js
diff --git a/chrome/browser/resources/google_now/cards.js b/chrome/browser/resources/google_now/cards.js
index 5e2481938e5a9cbbef943f5d6b9c6a1cd6be6f95..ea123192dd213c11e662fd55ebbba19d7fea3e4f 100644
--- a/chrome/browser/resources/google_now/cards.js
+++ b/chrome/browser/resources/google_now/cards.js
@@ -40,46 +40,38 @@ function buildCardSet() {
JSON.stringify(cardCreateInfo));
if (cardCreateInfo.previousVersion !== cardCreateInfo.version) {
- try {
- // Delete a notification with the specified id if it already exists, and
- // then create a notification.
- instrumented.notifications.create(
- cardId,
- cardCreateInfo.notification,
- function(newNotificationId) {
- if (!newNotificationId || chrome.runtime.lastError) {
- var errorMessage = chrome.runtime.lastError &&
- chrome.runtime.lastError.message;
- console.error('notifications.create: ID=' + newNotificationId +
- ', ERROR=' + errorMessage);
- return;
- }
-
- scheduleHiding(cardId, cardCreateInfo.timeHide);
- });
- } catch (error) {
- console.error('Error in notifications.create: ' + error);
- }
+ // Delete a notification with the specified id if it already exists, and
+ // then create a notification.
+ instrumented.notifications.create(
+ cardId,
+ cardCreateInfo.notification,
+ function(newNotificationId) {
+ if (!newNotificationId || chrome.runtime.lastError) {
+ var errorMessage = chrome.runtime.lastError &&
+ chrome.runtime.lastError.message;
+ console.error('notifications.create: ID=' + newNotificationId +
+ ', ERROR=' + errorMessage);
+ return;
+ }
+
+ scheduleHiding(cardId, cardCreateInfo.timeHide);
+ });
} else {
- try {
- // Update existing notification.
- instrumented.notifications.update(
- cardId,
- cardCreateInfo.notification,
- function(wasUpdated) {
- if (!wasUpdated || chrome.runtime.lastError) {
- var errorMessage = chrome.runtime.lastError &&
- chrome.runtime.lastError.message;
- console.error('notifications.update: UPDATED=' + wasUpdated +
- ', ERROR=' + errorMessage);
- return;
- }
-
- scheduleHiding(cardId, cardCreateInfo.timeHide);
- });
- } catch (error) {
- console.error('Error in notifications.update: ' + error);
- }
+ // Update existing notification.
+ instrumented.notifications.update(
+ cardId,
+ cardCreateInfo.notification,
+ function(wasUpdated) {
+ if (!wasUpdated || chrome.runtime.lastError) {
+ var errorMessage = chrome.runtime.lastError &&
+ chrome.runtime.lastError.message;
+ console.error('notifications.update: UPDATED=' + wasUpdated +
+ ', ERROR=' + errorMessage);
+ return;
+ }
+
+ scheduleHiding(cardId, cardCreateInfo.timeHide);
+ });
}
}
@@ -154,8 +146,9 @@ function buildCardSet() {
// Alarm to show the card.
var cardId = alarm.name.substring(cardShowPrefix.length);
instrumented.storage.local.get('notificationsData', function(items) {
- items.notificationsData = items.notificationsData || {};
console.log('cardManager.onAlarm.get ' + JSON.stringify(items));
+ if (!items || !items.notificationsData)
+ return;
var notificationData = items.notificationsData[cardId];
if (!notificationData)
return;
« no previous file with comments | « chrome/browser/resources/google_now/background_unittest.gtestjs ('k') | chrome/browser/resources/google_now/utility.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698