My program prompts the user to enter an IP address of an API, and then makes a call to that IP address. 2 of the error cases are
1: An invalid IP Address is entered. The POST call returns "net::ERR_ADDRESS_UNREACHABLE"
2: The certificate of the site at the given address is not trusted. The POST call returns "net::ERR_CERT_AUTHORITY_INVALID".
These two different scenarios should be addressed differently, but I can't find a way to tell which error is returned. Is there a way to distinguish between these returned errors with code?
Code:
function pingBridge(ip) {
var username = 'username';
var url = 'https://' + ip + '/api'
const result = new Promise(function(resolve, reject) {
fetch(url, {
method: 'POST',
body: JSON.stringify({'devicetype': username})
}).then(function(data) {
console.log('success')
console.log(data)
resolve(data.json())
}).catch(function(error) {
console.log('error')
console.log(error)
reject(error)
})
})
return result
}