axios

My implementation of debounce axios request left the promise in pending state forever, is there a better way?

此生再无相见时 提交于 2019-12-01 21:26:28
I need a simple debounce function with immediate always true. Without resorting to lodash and with the help of Can someone explain the "debounce" function in Javascript , I implemented it as following, function debounce(func, wait) { var timeout; return function() { if (!timeout) func.apply(this, arguments); clearTimeout(timeout); timeout = setTimeout(()=>{timeout = null}, wait); }; }; It works as expected until I need to debounce axios request. Assumed I have a debounced axios method, I would like the calling method to be as usual, which means my debounced axios method should return promise I

Axios with promise.prototype.finally doesn't work

筅森魡賤 提交于 2019-12-01 20:51:44
问题 Not sure what I am missing. Following the instructions here: https://github.com/mzabriskie/axios/blob/master/COOKBOOK.md I have npm installed both axios and npm install axios promise.prototype.finally --save . I am using Gulp with Browserify. var axios = require('axios'); require('promise.prototype.finally'); axios.get('http://google.com').finally(function(){ console.log('test'); }); Error: app-7ee90adab7.js:18780 Uncaught TypeError: axios.get(...).finally is not a function Update: This makes

Combine Nodejs + React Native + Axios + CORS

人走茶凉 提交于 2019-12-01 20:19:45
I am trying to make a request to my API (Node.JS) from the front-end (react-native) using Axios. But I am confused about the error I get. Here's the print stack trace of the error : Network Error - node_modules\axios\lib\core\createError.js:16:24 in createError - node_modules\axios\lib\adapters\xhr.js:87:25 in handleError - node_modules\event-target-shim\lib\event-target.js:172:43 in dispatchEvent - node_modules\react-native\Libraries\Network\XMLHttpRequest.js:554:29 in setReadyState - node_modules\react-native\Libraries\Network\XMLHttpRequest.js:387:25 in __didCompleteResponse - node_modules

How to set variable outside axios get [duplicate]

旧城冷巷雨未停 提交于 2019-12-01 20:11:30
问题 This question already has answers here : How do I return the response from an asynchronous call? (36 answers) Closed 2 years ago . I can't return a value using this function because it is empty. getNameById (id) { var name = '' axios.get('/names/?ids=' + id) .then(response => { this.response = response.data name = this.response[0].name }) .catch(e => { this.errors.push(e) }) // Is empty console.log('Name ' + name) return name } How do I access the name variable inside "then" and return it?

Axios with promise.prototype.finally doesn't work

╄→尐↘猪︶ㄣ 提交于 2019-12-01 19:04:58
Not sure what I am missing. Following the instructions here: https://github.com/mzabriskie/axios/blob/master/COOKBOOK.md I have npm installed both axios and npm install axios promise.prototype.finally --save . I am using Gulp with Browserify. var axios = require('axios'); require('promise.prototype.finally'); axios.get('http://google.com').finally(function(){ console.log('test'); }); Error: app-7ee90adab7.js:18780 Uncaught TypeError: axios.get(...).finally is not a function Update: This makes it work but do I need to do this? var promiseFinally = require('promise.prototype.finally');

Vuejs with axios request in vuex store: can't make more than one request, why?

别来无恙 提交于 2019-12-01 17:47:58
问题 I'm building some vuejs dashboard with vuex and axios, between others, and I've been struggling for a while on a pretty pesky problem: it seems I can't make more than one request! All subsequent calls fail with this error: Fetching error... SyntaxError: Failed to execute 'setRequestHeader' on 'XMLHttpRequest': 'Bearer {the_entire_content_of_the_previous_api_response}' is not a valid HTTP header field value. My store looks like that: import axios from "axios"; const state = { rawData1: null,

Request header field X-CSRF-TOKEN is not allowed by Access-Control-Allow-Headers

烈酒焚心 提交于 2019-12-01 17:46:24
问题 I'm making a get request to embed.rock using vue and axios. axios({ method: 'get', url: 'https://api.embed.rocks/api?url=' + this.url, headers: { 'x-api-key': 'my-key' } }) When I use a CDN to get vue and axios with an inline script my code works fine and I get a response back. When I reference the installed vue and axios scrpts with an external script the code no longer runs and I get the following error: Failed to load https://api.embed.rocks/api?url=https://www.youtube.com/watch?v=DJ6PD

Vuejs with axios request in vuex store: can't make more than one request, why?

帅比萌擦擦* 提交于 2019-12-01 17:42:40
I'm building some vuejs dashboard with vuex and axios, between others, and I've been struggling for a while on a pretty pesky problem: it seems I can't make more than one request! All subsequent calls fail with this error: Fetching error... SyntaxError: Failed to execute 'setRequestHeader' on 'XMLHttpRequest': 'Bearer {the_entire_content_of_the_previous_api_response}' is not a valid HTTP header field value. My store looks like that: import axios from "axios"; const state = { rawData1: null, rawData2: null }; const actions = { FETCH_DATA1: ({ commit }) => { if (!state.rawData1) return axios.get

Axios. How to get error response even when api return 404 error, in try catch finally

你。 提交于 2019-12-01 15:54:38
for e.g. (async() => { let apiRes = null; try { apiRes = await axios.get('https://silex.edgeprop.my/api/v1/a'); } catch (err) { console.error(err); } finally { console.log(apiRes); } })(); in finally , apiRes will return null. Even when the api get a 404 response, there is still useful information in the response that I would like to use. How can I use the error response in finally when axios throws error. https://jsfiddle.net/jacobgoh101/fdvnsg6u/1/ According to the documentation , the full response is available as a response property on the error. So I'd use that information in the catch

Has been blocked by CORS policy: Response to preflight request doesn’t pass access control check

两盒软妹~` 提交于 2019-12-01 15:46:12
I have created trip server. It works fine and we are able to make POST request by Insomnia but when we make POST request by axios on our front-end, it sends an error: has been blocked by CORS policy: Response to preflight request doesn’t pass access control check: It does not have HTTP ok status. Our request on axios: let config = { headers: { "Content-Type": "application/json", 'Access-Control-Allow-Origin': '*', } } let data = { "id": 4 } axios.post('http://196.121.147.69:9777/twirp/route.FRoute/GetLists', data, config) .then((res) => { console.log(res) }) .catch((err) => { console.log(err)