Skip to content

Instantly share code, notes, and snippets.

@Rajavn6789
Last active April 8, 2021 07:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Rajavn6789/d3454b6d0ab61aebd88329a712cffa6d to your computer and use it in GitHub Desktop.
Save Rajavn6789/d3454b6d0ab61aebd88329a712cffa6d to your computer and use it in GitHub Desktop.
// http.js
import axios from "axios";
export const httpETL = axios.create({
baseURL: "http://api.com"
});
httpETL.interceptors.request.use(
config => {
try {
config.headers.authToken = "IlavarasarJohn";
return config;
} catch (error) {
return config;
}
},
err => {
console.log("error", err);
}
);
// saga.js
import { httpETL } from "./http.js"
try {
const response = yield httpETL.post(`/approveJobs`, {
ids: 1
});
console.log('response', response);
} catch (e) {
if (e.response.status === 400) {
console.log('Unauthorized')
} else {
console.log('e', e)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment