title: Unhandled promise rejection: Error: Request failed with status code 500
body: <p>I am trying to call an api and I get the error "Unhandled promise rejection: Error: Request failed with status code 500". I dunno how did I get the error.I put the api call in componentDidMount. I am not sure whether the error comes from the redux implementation or from how I called the api.</p>
  
  <p>This is how I called the api. After a successful login, I put the username as a token and use it to call another api.</p>
  
  
  
  <pre class="lang-js prettyprint-override"><code> state={
      username: '',
      semcode: [
          {}
      ]
  }
  
  componentWillMount() {
      AsyncStorage.getItem('Login_token').then((token) =&gt; {
          console.log('this is coursescreen',token);
          let Login_token = token;
          this.setState({ username: Login_token });
  
      });   
  
  }
  
  componentDidMount(){
      this.props.getSemcode(this.state.username);  
  }
  componentWillReceiveProps(nextProps) {
      console.log('xx',nextProps);
      if (nextProps.semCode != undefined) {
          this.setState({ semcode: nextProps.semCode });
  
      }
  }
  </code></pre>
  
  <p>This is how I wrote my action file:</p>
  
  <pre class="lang-js prettyprint-override"><code>export const getSemcode = (username) =&gt; async dispatch =&gt; {
  
      let param = {
          nomatrik: username,
      }   
  
      console.log(`${helper.ROOT_URL}/result/GetListOfKodSesiSem`)
      let code_res = await 
      axios.post(`${helper.ROOT_URL}/result/GetListOfKodSesiSem`, param)
      console.log(code_res.data);    
      if (code_res.data.length &gt; 0) {
          const { code } = code_res.data;          
          dispatch({ type: SEMCODE_FETCH_SUCCESS, payload: { semCode: code }});
      }
  
  }   
  </code></pre>
  
  <p>This is how I wrote my reducer:</p>
  
  <pre class="lang-js prettyprint-override"><code>import { SEMCODE_FETCH_SUCCESS} from '../actions/types';
  
  const INITIAL_STATE={
  semCode:[],
  }
  export default function (state=INITIAL_STATE, action){
  switch(action.type){
      case SEMCODE_FETCH_SUCCESS:
        return action.payload
      default:
        return state;
  }
  }  
  </code></pre>
  
  <p>Can anyone help me pleaseeeeee          </p>
  
  <p><strong>Error Message</strong> </p>
  
  <blockquote>
    <p>Error received from axios.post: {"config":{"transformRequest":
    {},"transformResponse":{},"timeout":0,"xsrfCookieName":"XSRF-
    TOKEN","xsrfHeaderName":"X-XSRF-TOKEN","maxContentLength":-1,"headers":
    {"Accept":"application/json, text/plain, <em>/</em>","Content-
    Type":"application/json;charset=utf-8"},
    "method":"post","nomatrik":"BB16160907",
    "url":"<a href="https://smp.ums.edu.my/api/result/GetListOfKodSesiSem" rel="nofollow noreferrer">https://smp.ums.edu.my/api/result/GetListOfKodSesiSem</a>","data":"
    {\"Accept\":\"application/json\",\"Content-
    Type\":\"application/json\"}"},"request":
    {"UNSENT":0,"OPENED":1,"HEADERS_RECEIVED":2,"LOADING":3,"DONE":4,
    "readyState":4,"status":500,"timeout":0,"withCredentials":true,"upload":
    {},"_aborted":false,"_hasError":false,"_method":"POST","_response":"
    {\"Message\":\"An error has occurred.\"}",
    "_url":"<a href="https://smp.ums.edu.my/api/result/GetListOfKodSesiSem" rel="nofollow noreferrer">https://smp.ums.edu.my/api/result/GetListOfKodSesiSem</a>",
    "_timedOut":false,"_trackingName":"unknown",
    "_incrementalEvents":false,"responseHeaders":{"Date":"Sat, 30 Dec 2017
    03:58:25
    GMT","Content-Length":"36","X-Powered-By":"ARR/3.0","X-AspNet-
    Version":"4.0.30319","Expires":"-1","Content-Type":"application/json; 
    charset=utf-8","Server":"Microsoft-IIS/10.0","Pragma":"no-cache","Cache-
    Control":"no-cache"},"_requestId":null,"_headers":
    {"accept":"application/json, text/plain, <em>/</em>","content-
    type":"application/json;charset=utf-
    8"},"_responseType":"","_sent":true,"_lowerCaseResponseHeaders":{"date":"Sat,
    30 Dec 2017 03:58:25
    GMT","content-length":"36","x-powered-by":"ARR/3.0","x-
    aspnet-version":"4.0.30319","expires":"-1","content-type":"application/json;  charset=utf-8","server":"Microsoft-IIS/10.0","pragma":"no-cache","cache-
    control":"no-cache"},"_subscriptions":[],"responseURL":
    "<a href="https://smp.ums.edu.my/api/result/GetListOfKodSesiSem" rel="nofollow noreferrer">https://smp.ums.edu.my/api/result/GetListOfKodSesiSem</a>"},"response":{"data":
    {"Message":"An error has
    occurred."},"status":500,"headers":{"date":"Sat, 30  Dec 2017 03:58:25
    GMT","content-length":"36","x-powered-by":"ARR/3.0","x-
    aspnet-version":"4.0.30319","expires":"-1","content-type":"application/json;  charset=utf-8","server":"Microsoft-IIS/10.0","pragma":"no-cache","cache-
    control":"no-cache"},"config":{"transformRequest":{},"transformResponse":
    {},"timeout":0,"xsrfCookieName":"XSRF-TOKEN","xsrfHeaderName":"X-XSRF-
    TOKEN","maxContentLength":-1,"headers":{"Accept":"application/json, 
    text/plain,
    <em>/</em>","Content-Type":"application/json;charset=utf-8"},"method": "post","nomatrik":"BB16160907",
    "url":"<a href="https://smp.ums.edu.my/api/result/GetListOfKodSesiSem" rel="nofollow noreferrer">https://smp.ums.edu.my/api/result/GetListOfKodSesiSem</a>","data":"
    {\"Accept\":\"application/json\",\"Content-
    Type\":\"application/json\"}"},"request":
    {"UNSENT":0,"OPENED":1,"HEADERS_RECEIVED":2,"LOADING":3,"DONE":4,
    "readyState":4,"status":500,"timeout":0,"withCredentials":true,"upload":
    {},"_aborted":false,"_hasError":false,"_method":"POST","_response":"
    {\"Message\":\"An error has occurred.\"}",
    "_url":"<a href="https://smp.ums.edu.my/api/result/GetListOfKodSesiSem" rel="nofollow noreferrer">https://smp.ums.edu.my/api/result/GetListOfKodSesiSem</a>",
    "_timedOut":false,"_trackingName":"unknown","_incrementalEvents":false, "responseHeaders":{"Date":"Sat, 30 Dec 2017 03:58:25 GMT","Content-
    Length":"36","X-Powered-By":"ARR/3.0","X-AspNet-
    Version":"4.0.30319","Expires":"-1","Content-Type":"application/json; 
    charset=utf-8","Server":"Microsoft-IIS/10.0","Pragma":"no-cache","Cache-
    Control":"no-cache"},"_requestId":null,"_headers":
    {"accept":"application/json, text/plain, <em>/</em>","content-
    type":"application/json;charset=utf-
    8"},"_responseType":"","_sent":true,"_lowerCaseResponseHeaders":{"date":"Sat,
    30 Dec 2017 03:58:25
    GMT","content-length":"36","x-powered-by":"ARR/3.0","x-
    aspnet-version":"4.0.30319","expires":"-1","content-type":"application/json;  charset=utf-8","server":"Microsoft-IIS/10.0","pragma":"no-cache","cache-
    control":"no-cache"},"_subscriptions":
    [],"responseURL":"<a href="https://smp.ums.edu.my/api/result/GetListOfKodSesiSem" rel="nofollow noreferrer">https://smp.ums.edu.my/api/result/GetListOfKodSesiSem</a>"}}}</p>
  </blockquote>
  
  <p>Login action:</p>
  
  <pre class="lang-js prettyprint-override"><code>export const attemptLogin = (username, password) =&gt; async dispatch =&gt; {
  
  let param = {
      txtNomatrik: username,
      txtPwd: password,
      public_key: helper.PUBLIC_KEY,
      secret_key: helper.SECRET_KEY
  
  }
  
  console.log(`${helper.ROOT_API_URL}/v1/basic/ad/std/login`)
  let login_res = await 
  axios.post(`${helper.ROOT_API_URL}/v1/basic/ad/std/login`, param)
  
  console.log(login_res.data);
  await AsyncStorage.setItem('jwtToken',login_res.data.token);
  if (login_res.data.status == 'Successful login') {
      const { login } = login_res.data;    
      dispatch({ type: LOGIN_SUCCESS});   
  }
  }   
  </code></pre>