about summary refs log blame commit diff
path: root/app/assets/javascripts/components/api.jsx
blob: 93cfc8046350328ccaff24f539b2392c2fc4f077 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
                          

                                          





                                      
  





                                                                               



                              
    
import axios from 'axios';
import LinkHeader from 'http-link-header';

export const getLinks = response => {
  const value = response.headers.link;

  if (!value) {
    return { refs: [] };
  }

  return LinkHeader.parse(value);
};

export default getState => axios.create({
  headers: {
    'Authorization': `Bearer ${getState().getIn(['meta', 'access_token'], '')}`
  },

  transformResponse: [function (data) {
    try {
      return JSON.parse(data);
    } catch(Exception) {
      return data;
    }
  }]
});