Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Axios update #148

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "web-scraper-chrome-extension",
"version": "0.5",
"version": "0.5.1",
"description": "Web data extraction tool implemented as chrome extension",
"scripts": {
"lint": "eslint --ext .js src",
Expand All @@ -18,9 +18,8 @@
}
},
"dependencies": {
"@vespaiach/axios-fetch-adapter": "^0.3.1",
"@babel/runtime": "^7.10.5",
"axios": "^0.26.1",
"axios": "1.7.7",
"bootstrap": "3.4.1",
"d3": "^3.3.8",
"icanhaz": "0.10.3",
Expand Down
16 changes: 5 additions & 11 deletions src/scripts/StoreRestApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ import axios from 'axios';
import Sitemap from './Sitemap';
import StorePouchDB from './StorePouchDB';
import urlJoin from 'url-join';
import fetchAdapter from '@vespaiach/axios-fetch-adapter';

export default class StoreRestApi {
constructor(config, baseUrl, sitemapsPath = 'sitemaps/') {
this.localDataStore = new StorePouchDB(config);
this.axiosInstance = axios.create({
baseURL: baseUrl,
adapter: fetchAdapter,
});
this.axiosInstance.defaults.headers.post['Content-Type'] = 'application/json';
this.axiosInstance.defaults.headers.put['Content-Type'] = 'application/json';
Expand All @@ -19,15 +17,11 @@ export default class StoreRestApi {

setAxiosInterceptors() {
this.axiosInstance.interceptors.response.use(response => {
//TODO return it when change axios to fetch
// const [contentType] = response.headers['content-type'].split(';');
// if (contentType !== 'application/json') {
// const error = new Error(`Incorrect response type`);
// return Promise.reject(error);
// }
// if (response.headers['content-type']) {
// console.log(response.headers['content-type']);
// }
const [contentType] = response.headers['content-type'].split(';');
if (contentType !== 'application/json') {
const error = new Error(`Incorrect response type`);
return Promise.reject(error);
}
return response;
});
}
Expand Down
3 changes: 0 additions & 3 deletions src/scripts/StoreTalismanApi.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import axios from 'axios';
import fetchAdapter from '@vespaiach/axios-fetch-adapter';
import StoreRestApi from './StoreRestApi';
import urlJoin from 'url-join';
import * as browser from 'webextension-polyfill';
Expand Down Expand Up @@ -36,7 +35,6 @@ export default class StoreTalismanApi extends StoreRestApi {
const response = await axios({
method: 'get',
url: urlJoin(this.axiosInstance.defaults.baseURL, 'meta.json'),
adapter: fetchAdapter,
});
return response.data.APP_NAME;
}
Expand Down Expand Up @@ -102,7 +100,6 @@ export default class StoreTalismanApi extends StoreRestApi {
const response = await axios({
method: 'get',
url: `${tUrl}/oauth/token`,
adapter: fetchAdapter,
});
try {
if (response.data.preferred_username) {
Expand Down