<commit_before>'use strict'
import parallel from 'async/parallel'
import _ from 'lodash'
export default function (app) {
  app.factory('notificationService', function (Service, $http) {
    "ngInject"
    let httpTimeout = 10000
    let notifications, pending, cbs = []

    function getNotifications(cb) {
      if (notifications) {
        return cb(null, notifications)
      }
      cbs.push(cb)
      // concurrency control: only fetch notifications once
      if (pending) {
        return
      }
      pending = true
      Service.find({}, function (list) {
          let notificationList = list.filter(function (e, i) {
            return e.notificationRestApiUrl
          }).reduce(function (p, e, i) {
            p[e.notificationRestApiUrl] = p[e.notificationRestApiUrl] || []
            p[e.notificationRestApiUrl].push(e.name)
            return p
          }, {})
          let notificationRequests = _.map(notificationList, function (v, k, c) {
            return function (cb) {
              $http.get(k, {timeout: httpTimeout}).then(response => {
                // make sure the serviceName attribute in response.data exists in v
                let inServiceNotifications = response.data.filter(function (e, i) {
                  return v.indexOf(e.serviceName) >= 0
                })
                cb(null, inServiceNotifications.map(function (e) {
                  e.baseUrl = k
                  return e
                }))
              })
            }
          })
          parallel(notificationRequests, function (err, results) {
            let concatenatedResults = results.reduce(function (p, e) {
              return p.concat(e)
            }, [])
            notifications = concatenatedResults
            pending = false
            cbs.forEach(function (e, i) {
              e(null, concatenatedResults)
            })
          })
        }
      )
    }

    return {
      get: getNotifications,
      getUnreadCount: function (cb) {
        function filterUnread(e, i) {
          return e.state === 'new'
        }

        if (notifications) {
          return cb(null, notifications.filter(filterUnread).length)
        }
        getNotifications(function (err, data) {
          return cb(null, data.filter(filterUnread).length)
        })<commit_msg>handle errors when retrieving notifications.<commit_after>'use strict'
import parallel from 'async/parallel'
import _ from 'lodash'
export default function (app) {
  app.factory('notificationService', function (Service, $http) {
    "ngInject"
    let httpTimeout = 10000
    let notifications, pending, cbs = []

    function getNotifications(cb) {
      if (notifications) {
        return cb(null, notifications)
      }
      cbs.push(cb)
      // concurrency control: only fetch notifications once
      if (pending) {
        return
      }
      pending = true
      Service.find({}, function (list) {
          let notificationList = list.filter(function (e, i) {
            return e.notificationRestApiUrl
          }).reduce(function (p, e, i) {
            p[e.notificationRestApiUrl] = p[e.notificationRestApiUrl] || []
            p[e.notificationRestApiUrl].push(e.name)
            return p
          }, {})
          let notificationRequests = _.map(notificationList, function (v, k, c) {
            return function (cb) {
              $http.get(k, {timeout: httpTimeout}).then(response => {
                // make sure the serviceName attribute in response.data exists in v
                let inServiceNotifications = response.data.filter(function (e, i) {
                  return v.indexOf(e.serviceName) >= 0
                })
                cb(null, inServiceNotifications.map(function (e) {
                  e.baseUrl = k
                  return e
                }))
              }, err => {
                cb(null, null)
              })
            }
          })
          parallel(notificationRequests, function (err, results) {
            let concatenatedResults = results.reduce(function (p, e) {
              return e ? p.concat(e) : p
            }, [])
            notifications = concatenatedResults
            pending = false
            cbs.forEach(function (e, i) {
              e(null, concatenatedResults)
            })
          })
        }
      )
    }

    return {
      get: getNotifications,
      getUnreadCount: function (cb) {
        function filterUnread(e, i) {
          return e.state === 'new'
        }

        if (notifications) {
          return cb(null, notifications.filter(filterUnread).length)
        }
        getNotifications(function (err, data) {
          return cb(null, data.filter(filterUnread).length)
        })
{'fraction_non_alphanumeric': 0.10556499575191164, 'fraction_numerical': 0.002548853016142736, 'mean_word_length': 1.7346109175377469, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7580494', 'n_tokens_mistral': 1274, 'n_tokens_neox': 1226, 'n_words': 297}