axios

How to catch and handle error response 422 with Redux/Axios?

回眸只為那壹抹淺笑 提交于 2019-12-02 17:16:32
I have an action making a POST request to the server in order to update a user's password, but I'm unable to handle the error in the chained catch block. return axios({ method: 'post', data: { password: currentPassword, new_password: newPassword }, url: `path/to/endpoint` }) .then(response => { dispatch(PasswordUpdateSuccess(response)) }) .catch(error => { console.log('ERROR', error) switch (error.type) { case 'password_invalid': dispatch(PasswordUpdateFailure('Incorrect current password')) break case 'invalid_attributes': dispatch(PasswordUpdateFailure('Fields must not be blank')) break } })

Actions must be plain Objects in React/Redux?

主宰稳场 提交于 2019-12-02 17:14:47
问题 the problem I'm running into is Actions must be plain objects when passing data through my action creators. Basically I'm trying to capture user input through the click of a button, and based on what button (view) is clicked the event.target.innerHTML is passed to the action creator fetchDataAsync(view) which then performs a GET request via axios and dispatches based on what view was selected. I'm still new with Redux, though, and I'm unsure of what I'm doing wrong here. I've seen an async

How to handle 401 (Authentication Error) in axios and react?

醉酒当歌 提交于 2019-12-02 16:24:43
I have one file request.js which contains wrapper for axios ajax request. I am calling request function from multiple react components and when one of the request fails I want to refresh the token and retry all the failed requests again. I can use intercepters, but I don't know how to implement it. Please help. request.js var client = axios.create({ baseURL: 'http://192.168.1.3:3000', headers: { appID: 8, version: "1.1.0", empID: localStorage.getItem('empID'), token: localStorage.getItem('accessToken') } }); const request = function(options) { const onSuccess = function(response) { console

Sending POST axios request with Array of objects

自闭症网瘾萝莉.ら 提交于 2019-12-02 16:06:24
问题 I am trying to send a POST request with an array of objects using axios. But I am having 500 internal server error and no exceptions on the server. When I send a single object it works fine but not with an array of objects, in this case, it not even trigger my REST service. Does someone have any idea? My array of objects looks like this:- arrayofObjects:[ {}, {}, several objects here ] POST request:- axios.post(URL,JSON.stringify(this.arrayofObjects), headers) .then(response=>{ returnData =

TypeError: this.state.patients.map is not a function

£可爱£侵袭症+ 提交于 2019-12-02 15:13:23
问题 i am new in react js,and i am learning to create a React application and I got a problem with mapping function: Here's my request and how I am attempting to render the data: class Patients extends Component { constructor(props) { super(props) this.state = { patients: [] } } componentDidMount() { api.getPatients() .then( patients => { console.log( patients) this.setState({ patients: patients }) }) .catch(err => console.log(err)) } render() { return ( <div className=" Patientss"> <h2>List of

from origin 'xxx' has been blocked by CORS policy: [duplicate]

扶醉桌前 提交于 2019-12-02 14:01:38
This question already has an answer here: OAuth2.0 - authentication using GitHub with front-end and back-end running on different servers. CORS error 2 answers I'm trying the most basic get request from the browser and it fails due to CORs issues. axios.get( "https://github.com/login/oauth/authorize?client_id={ID}" ); Is it just not possible to make this request from the browser? I'm trying to understand how it's possible to click a button and have this link work. from origin ' http://localhost:3001 ' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the

JS Axios - how to get response body in event of error?

我怕爱的太早我们不能终老 提交于 2019-12-02 11:06:32
I want to be able to get the response body back from an Axios error catch. I am using axios v0.18.0. My axios code looks like this: let service = axios.create({ baseURL: "https://baseUrl.azurewebsites.net", responseType: "json" }); service.defaults.headers.common['authorization'] = `Bearer ${token}`; service.post("/api/method", params).then(result => { console.log('success',result); }).catch(error=>{ console.log('error'); console.log(error); }); My API call is returning a 400 error as I expected, given my inputs. So I am hitting the catch block. However I'm not able to retrieve the error

Sending POST axios request with Array of objects

大兔子大兔子 提交于 2019-12-02 10:54:45
I am trying to send a POST request with an array of objects using axios. But I am having 500 internal server error and no exceptions on the server. When I send a single object it works fine but not with an array of objects, in this case, it not even trigger my REST service. Does someone have any idea? My array of objects looks like this:- arrayofObjects:[ {}, {}, several objects here ] POST request:- axios.post(URL,JSON.stringify(this.arrayofObjects), headers) .then(response=>{ returnData = (response.data); }) .catch(ext=>{ alert(ext.response.data); }) Here is the REST Service(not the complete

Actions must be plain Objects in React/Redux?

梦想的初衷 提交于 2019-12-02 10:44:37
the problem I'm running into is Actions must be plain objects when passing data through my action creators. Basically I'm trying to capture user input through the click of a button, and based on what button (view) is clicked the event.target.innerHTML is passed to the action creator fetchDataAsync(view) which then performs a GET request via axios and dispatches based on what view was selected. I'm still new with Redux, though, and I'm unsure of what I'm doing wrong here. I've seen an async action performed inside an action creator before... Component connected with Redux: class ViewSelector

TypeError: this.state.patients.map is not a function

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-02 08:12:20
i am new in react js,and i am learning to create a React application and I got a problem with mapping function: Here's my request and how I am attempting to render the data: class Patients extends Component { constructor(props) { super(props) this.state = { patients: [] } } componentDidMount() { api.getPatients() .then( patients => { console.log( patients) this.setState({ patients: patients }) }) .catch(err => console.log(err)) } render() { return ( <div className=" Patientss"> <h2>List of Patient</h2> {this.state.patients.map((c, i) => <li key={i}>{c.name}</li>)} </div> ); } } export default