Download PDF from http response with Axios

As @Sandip Nirmal suggested I’ve used downloadjs and that worked out pretty good! Had to make a few adjustments to my code but in the end it worked out. My new code // npm i downloadjs import download from ‘downloadjs’ // method downloadFile(file) { const specificationId = this.$route.params.specificationId; axios .get(`${this.$API_URL}/api/v1/suppliersmanagement/product-specifications/${specificationId}/fileupload/${file.id}/download`, { headers: this.headers, responseType: ‘blob’, … Read more

How to use axios to make an https call?

Axios https proxy support is borked if using https proxies. Try passing the proxy through httpsProxyAgent using http. const axios = require(‘axios’); const httpsProxyAgent = require(‘https-proxy-agent’); const httpsAgent = new httpsProxyAgent(‘http://username:pass@myproxy:port’); // or const httpsAgent = new httpsProxyAgent({ host: ‘myproxy’, port: 9999 }); const config = { url: ‘https://google.com’, httpsAgent } axios.request(config).then((res) => console.log(res)).catch(err => … Read more

How to use Vue.prototype or global variable in Vue 3?

You could use provide/inject or define a global config property, which replaces Vue.prototype in Vue 3: 1. provide/inject (for Composition or Options API) Provide import axios from ‘axios’; const app = Vue.createApp(App); app.provide(‘$axios’, axios); // Providing to all components during app creation Inject Composition API: const { inject } = Vue; … setup() { const … Read more

“The final argument passed to useEffect changed size between renders”, except I don’t think it does?

If you have a useEffect(() => {}, itemArray) and you modify itemArray, you will get this error. this is probably just a typo. I did this when I had a list of items I was using from state. It didn’t catch it because it was an array. You need [] around the itemArray. useEffect(() => … Read more

axios gives me converting circular structure to json error while sending the data

axios.post(‘https://api.sandbox.xyz.com/v1/order/new’, JSON.stringify({ “request”: “/v1/order/new”, “nonce”: 123462, “client_order_id”: “20150102-4738721”, “symbol”: “btcusd”, “amount”: “1.01”, “price”: “11.13”, “side”: “buy”, “type”: “exchange limit” }), config) .then(function(response) { res.send(response.data) }) .catch(function(error) { res.send({ status: ‘500’, message: error }) });

How to get response times from Axios

You can use the interceptor concept of axios. Request interceptor will set startTime axios.interceptors.request.use(function (config) { config.metadata = { startTime: new Date()} return config; }, function (error) { return Promise.reject(error); }); Response interceptor will set endTime & calculate the duration axios.interceptors.response.use(function (response) { response.config.metadata.endTime = new Date() response.duration = response.config.metadata.endTime – response.config.metadata.startTime return response; }, … Read more

Mock inner axios.create()

OK I got it. Here is how I fixed it! I ended up doing without any mocking libraries for axios! Create a mock for axios in src/__mocks__: // src/__mocks__/axios.ts const mockAxios = jest.genMockFromModule(‘axios’) // this is the key to fix the axios.create() undefined error! mockAxios.create = jest.fn(() => mockAxios) export default mockAxios Then in your … Read more

Missing headers in Fetch response

The Headers class instance that fetch returns is an iterable, as opposed to a plain object like axios returns. Some iterable’s data, such as Headers or URLSearchParams, aren’t viewable from the console, you have to iterate it and console.log each element, like: fetch(‘http://localhost:9876/test/sample-download’, { method: ‘post’, headers: {}, body: {} }) .then(response => { // … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)