30 lines
		
	
	
		
			No EOL
		
	
	
		
			750 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			30 lines
		
	
	
		
			No EOL
		
	
	
		
			750 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
import axios from 'axios';
 | 
						|
 | 
						|
import SuperJSON from 'superjson';
 | 
						|
 | 
						|
axios.defaults.withCredentials = true; // Enable sending cookies with requests
 | 
						|
 | 
						|
axios.interceptors.response.use(
 | 
						|
  (response) =>
 | 
						|
  {
 | 
						|
    //If the response content type is application/json, we want to parse it with SuperJSON
 | 
						|
    if (response.headers['content-type'] && response.headers['content-type'].includes('application/json'))
 | 
						|
    {
 | 
						|
      try
 | 
						|
      {
 | 
						|
        response.data = SuperJSON.parse(JSON.stringify(response.data));
 | 
						|
      }
 | 
						|
      catch (error)
 | 
						|
      {
 | 
						|
        console.error('Error deserializing response data:', error);
 | 
						|
      }
 | 
						|
    }
 | 
						|
    return response;
 | 
						|
  },
 | 
						|
  (error) =>
 | 
						|
  {
 | 
						|
    // Handle errors here if needed
 | 
						|
    return Promise.reject(error);
 | 
						|
  }
 | 
						|
);
 | 
						|
export default axios; |