I have a function in my logic.js file that retrieves the latitude and longitude of a plane from an api:
function getLocation(){
var url = 'https://opensky-network.org/api/states/all?time=1458564121&icao24=3c6444'
return fetch(url) // Call the fetch function passing the url of the API as a parameter
.then(function(resp){
data = resp.json() // Transform the data into json
return data
}).then(function(data) {
lat = data.states[0][5]
long = data.states[0][6]
lat = lat.toString()
long = long.toString()
location = [lat,long]
return location
})
}
}
when I test this function on the playground it successfully retrieves the latitude and longitude of the plane. However when I try to carry out the same function through the composer REST sever I get the following error:
Error trying invoke business network. Error: No valid responses from any peers.\nResponse from attempted peer comms was an error: Error: chaincode error (status: 500, message: ReferenceError: identifier 'fetch' undefined)
Does anyone know why this is the case?