Last active
November 23, 2015 22:42
-
-
Save adregan/6872ff922910ea1fb9a5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var requests = require('superagent'); | |
var fetch = function(url, options) { | |
let method = options.method; | |
return new Promise((resolve, reject) => { | |
requests[method](url) | |
.end((err, res) => { | |
if (err) { | |
reject(err); | |
} | |
else { | |
resolve(res); | |
} | |
}) | |
}) | |
} | |
fetch('http://localhost:8888', {method: 'patch'}) | |
.then(res => console.log(`SUCCESS: {JSON.stringify(res.body)}`)) | |
.catch(err => { | |
if (err.crossDomain) { | |
console.error('Cross domain error!!!') | |
fetch('http://localhost:8888', {method: 'put'}) | |
.then(res => console.log(`SUCCESS: {JSON.stringify(res.body)}`)) | |
.catch(err => { | |
console.error('¯\_(ツ)_/¯'); | |
}) | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment