Created
          June 15, 2016 07:23 
        
      - 
      
 - 
        
Save benjaminreid/ee6e1274ea5c360ed59937327bed14da to your computer and use it in GitHub Desktop.  
  
    
      This file contains hidden or 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
    
  
  
    
  | 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