import { Failure, Success } from 'data.validation'; // Report unhandled promise rejections (bugs) window.onunhandledrejection = (event) => { // Raven.captureException(event.reason); console.error('Unhandled rejection:', event.reason); }; function fetchRepo(name) { return fetch(`https://api.github.com/repos/${name}`).then((response) => response.json().then((data) => response.ok ? Success(data) : Failure(data) ) ); } function getStars(name) { fetchRepo(name).then((result) => { const message = result.fold( (error) => `Fetching '${name}' failed: ${error.message}`, (repo) => `${name}: ${repo.stargazers_count} stars` ); console.log(message); }); } getStars('babel/babel'); getStars('facebook/react'); getStars('fson/repo_does_not_exist');