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("--------------------------------------------------")
                // 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 if (error.request) {
                console.log("*************************")

                // The request was made but no response was received
                // `error.request` is an instance of XMLHttpRequest in the browser and an instance of
                // http.ClientRequest in node.js
                console.log(error.request);
            } else {
                console.log("++++++++++++++++++++++++")
                // Something happened in setting up the request that triggered an Error
                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');