Skip to content

Instantly share code, notes, and snippets.

@benjaminreid
Created June 15, 2016 07:23
Show Gist options
  • Save benjaminreid/ee6e1274ea5c360ed59937327bed14da to your computer and use it in GitHub Desktop.
Save benjaminreid/ee6e1274ea5c360ed59937327bed14da to your computer and use it in GitHub Desktop.
function request() {
let options = {
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Authorization': '4f2a8bb583700b1291763f0832d718b628e9abea813b5119616d7b12aa1fb531'
},
}
return fetch('http://localhost:3000/api/user', options)
.then(response => response.json())
.then((json) => {
let { status, errors } = json;
if (status == 'unauthorized' && errors[0].error == 'invalid_token') {
// spoof the refresh request
return fetch('http://localhost:3000/api/user', options)
.then(response => response.json())
.then((json) => {
// pretend we have the token
return { 'woop': true };
})
.catch((error) => {
console.log('2', error);
})
}
})
.catch((error) => {
console.log('1:', error)
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment