Handling Axios error in React

Better way to handle API error with Promise catch method*. axios.get(people) .then((response) => { // Success }) .catch((error) => { // Error if (error.response) { // The request was made and the server responded with a status code // that falls out of the range of 2xx // console.log(error.response.data); // console.log(error.response.status); // console.log(error.response.headers); } else … Read more

NodeJS, Axios – post file from local server to another server

The 2 oldest answers did not work for me. This, however, did the trick: const FormData = require(‘form-data’); // npm install –save form-data const form = new FormData(); form.append(‘file’, fs.createReadStream(file.path)); const request_config = { headers: { ‘Authorization’: `Bearer ${access_token}`, …form.getHeaders() } }; return axios.post(url, form, request_config); form.getHeaders() returns an Object with the content-type as well … Read more

Calling locally hosted server from Expo App

You can get the IP address at runtime using the Expo manifest: import Constants from “expo-constants”; const { manifest } = Constants; const api = (typeof manifest.packagerOpts === `object`) && manifest.packagerOpts.dev ? manifest.debuggerHost.split(`:`).shift().concat(`:3000`) : `api.example.com`; This will set api constant to the address of your local development machine in development mode and to whatever address … Read more

How to overcome the CORS issue in ReactJS

the simplest way what I found from a tutorial of “TraversyMedia” is that just use https://cors-anywhere.herokuapp.com in ‘axios’ or ‘fetch’ api https://cors-anywhere.herokuapp.com/{type_your_url_here} e.g. axios.get(`https://cors-anywhere.herokuapp.com/https://www.api.com/`) and in your case edit url as url: ‘https://cors-anywhere.herokuapp.com/https://www.api.com’,

Automating access token refreshing via interceptors in axios

I may have found a way much simpler to handle this : use axios.interceptors.response.eject() to disable the interceptor when I call the /api/refresh_token endpoint, and re-enable it after. The code : /** * Wrap the interceptor in a function, so that i can be re-instantiated */ function createAxiosResponseInterceptor() { const interceptor = axios.interceptors.response.use( (response) => … Read more

Axios interceptors and asynchronous login

Just use another promise 😀 axios.interceptors.response.use(undefined, function (err) { return new Promise(function (resolve, reject) { if (err.status === 401 && err.config && !err.config.__isRetryRequest) { serviceRefreshLogin( getRefreshToken(), success => { setTokens(success.access_token, success.refresh_token) err.config.__isRetryRequest = true err.config.headers.Authorization = ‘Bearer ‘ + getAccessToken(); axios(err.config).then(resolve, reject); }, error => { console.log(‘Refresh login error: ‘, error); reject(error); } ); } … Read more

Progress Bar with axios

I think the problem is with the “progress” event itself, as you can read in Axios configuration itself progress is not supported. instead you should listen to onUploadProgress or onDownloadProgress Another issue is getting the totalLength which i tried doing the following way: look if lengthComputable, if not try and get the length from the … Read more

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