react axios post 500 (internal server error) code example
Example 1: react js http post 500 internal server error
export default function callApi2(endpoint, method = 'GET', body) {
let headers = { 'content-type': 'application/json' }
console.log(body);
return axios({
method: method,
url: `${Config.API_URL2}/${endpoint}`,
data: JSON.stringify(body),
headers: { 'content-type': 'application/json' },
}).catch(err => {
console.log(err);
});
Example 2: POST http://localhost:5001/api/v1/identity/login 500 (Internal Server Error) LoginForm.jsx:30 Error: Request failed with status code 500 at createError (createError.js:16) at settle (settle.js:17) at XMLHttpRequest.handleLoad (xhr.js:61) react
axios.post(
config.apiGateway.URL + ".../signin",
payload
).then(response => {
console.log(response)
if(response.status == 200){
console.log("Login successfull");
this.setState({token: response.data.JWT_TOKEN});
} else {
console.log(response.status)
this.setError()
}
}).catch(error => {
this.setError()
console.log(error)
if (error.response) {
console.log("--------------------------------------------------")
console.log(error.response.data);
console.log(error.response.status);
console.log(error.response.headers);
} else if (error.request) {
console.log("*************************")
console.log(error.request);
} else {
console.log("++++++++++++++++++++++++")
console.log('Error', error.message);
}
console.log(error.config);
})
Example 3: react js http post 500 internal server error
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers', 'Content-Type');
res.header('Access-Control-Allow-Methods','GET, POST, PATCH, PUT, DELETE, OPTIONS');