0

I am trying to create a currency exchange app and anytime I deploy the code to my org via VS Code, I keep getting the error Action failed: flexipage:runtimeComponent$controller$init [Headers is not a constructor]

Please see my code below;

const currencyname=[
{label: 'USD',value: 'USD'},
{label: 'EUR',value: 'EUR'},
{label: 'GBP',value: 'GBP'},
{label: 'NGN',value: 'NGN'},
]
export default class HTTPCallout extends LightningElement {
    @track fromCurrencyValue;
    @track toCurrencyValue;
    @track currencyname=currencyname;
    @track toCurrencyOptions=currencyname;
    

    handleNumberChange(event){
        let val = this.template.querySelector('input[data-id=currency amount]').numberFieldValue;
        this.numberFieldValue=event.detail.value;
        console.log('This is the number to be converted=>'+this.numberFieldValue);
    }

    handleFromCurrencyChange(event){
        this.fromCurrencyValue=event.detail.value;
        console.log('This is the fromcurrencyvalue=>' +this.fromCurrencyValue);
    }
    handletoCurrencyChange(event){
        this.toCurrencyValue=event.detail.value;
        console.log('This is the tocurrencyvalue=>' +this.toCurrencyValue);
    }
    handleCurrencyConversion(){
        fetch('https://api.apilayer.com/exchangerates_data/convert?to='+this.toCurrencyValue+'&from='+this.fromCurrencyValue+'&amount='+this.numberFieldValue
        +'&apikey= API Key',
    {
            method:"GET",
            headers:{
                "Content-type":"application/json",
                "Authorization":"OAuth access token",
            }

    })
    .then((response)=>
    {
        return response.json();
    })
    .then((jsonResponse)=>{
        let objData={
            From_Currency_Name:'',
            From_Currency_Code:'',
            To_Currency_Name:'',
            To_Currency_Code:'',
            Last_Refreshed:'',
        };
        window.console.log('jsonresponse ==>'+JSON.stringify(jsonResponse));
        let exchangeData=jsonResponse['Realtime Currency Exchange Rate'];
        window.console.log('exchangeData==> '+JSON.stringify(exchangeData))
        objData.From_Currency_Name=exchangeData['1. From_Currency_Name'];
        objData.From_Currency_Code=exchangeData['2. From_Currency_Code'];
        objData.To_Currency_Name=exchangeData['4. To_Currency_Name'];
        objData.To_Currency_Code=exchangeData['3. To_Currency_Code'];
        objData.Last_Refreshed=exchangeData['6. Last_Refreshed'];
        window.console.log('objData='+objData);

    }).catch(error=>{
        window.console.log('callout error '+JSON.stringify(error));
    })
    
    }
}

What could I be doing wrong?

3
  • I'm trying this code into my org and it works. Did you add to a flexipage already? Could you remove from the flexipage first before deploying to the org? Commented Nov 8, 2022 at 11:35
  • @LuismaWhatakuai I have even deleted the entire project and I want to rewrite the code but the error still pops up anytime I log in. Do you think I should de-link my org from VS Code and re-link?
    – Afonja
    Commented Nov 8, 2022 at 11:59
  • I think it's something is already in your org... a component into a flexipage or a custom flexipage... Can you check what customizations can you have already deployed and could be failing? Maybe an aura component or a custom flexipage. Commented Nov 8, 2022 at 12:19

0

You must log in to answer this question.