langbung01 icon

axios get request and return

langbung01 | PRO | 09/05/18 05:02:05 PM UTC | 0 ⭐ | 590 👁️ | Never ⏰ | []
JavaScript |

1.35 KB

|

None

|

0 👍

/

0 👎

// return form request api
    checkLOA = async (id) => {
      return new Promise((resolve,reject) => {
        const url = process.env.MIX_BACKEND_IP;
        axios.get(`${url}/api/loa_level/${id}`)
          .then((res) => {
            resolve(res.data.data.loa_level);
          })
          .catch((err) => {
            reject(err);
          });
      });
    }
 
 activateMobile = async (id) => {
      let a;
        try {
             a = await this.checkLOA(this.props.accountInfo.account.id);
        } catch (e) {
            console.log(e)
            a = -1 ;
        }
      if (a >= 1) {
          this.setState({
              mobileId: id,
              openModalConfirmMobile: true,
          });
      } else {
          this.props.dispatch(error({
              title: 'Data not complete.',
              message: 'Please fill in the data and confirming the e-mail before do this.',
          }));
      }
    };
 
 
/*****************************************************************/
//with error header
 
let url = "http://203.154.100.147/api/checkbusiness_owner/"+id_card_value;
axios.get(url,{
    headers:{Authorization:"Bearer "+accessToken}
})
    .then(function (response) {
        
        console.log(response['data']);
    })
    .catch(function (error) {
        
        console.log(error);
    })

Comments