I have a script that uses node-fetch and is asynchronous when making fetch calls. I've tried to implement error handling, yet I have had no luck finding a solution. A snippet of my code is available below, and I need to find a way to detect when the API being called sends back an error.
var url = "https://identitytoolkit.googleapis.com/v1/accounts:signInWithPassword?key=API KEY";
var payload = {
email: email,
password: password,
returnSecureToken: true
};
var options = {
method: 'post',
contentType: 'application/json',
body: JSON.stringify(payload)
};
var res = await fetch(url, options);
var result = await res.json();
response.send(JSON.stringify(result))
Thanks And I appreciate any attempt at resolving this issue!