aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/lib/bug-notifier.js
blob: d6a2ed2c936ffbd7d011700b625d39154ab5935f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
class BugNotifier {
  notify (uri, message) {
    return postData(uri, message)
      .then(data => console.log(data)) // JSON from `response.json()` call
      .catch(error => console.error(error))
  }
}

function postData(uri, data) {

  return fetch(url, {
    body: JSON.stringify(data), // must match 'Content-Type' header
    credentials: 'same-origin', // include, same-origin, *omit
    headers: {
      'content-type': 'application/json'
    },
    method: 'POST', // *GET, POST, PUT, DELETE, etc.
    mode: 'cors', // no-cors, cors, *same-origin
  })
  .then(response => response.json()) // parses response to JSON
}

module.exports = BugNotifier