I created the next function that should return the response, data and error in case if exists.
const login = function(cb) {
fetch('https://jsonplaceholder.typicode.com/todos/1')
.then((response) => {
cb(null, null, response);
return response.json();
})
.then((data) => {
cb(data, null, null);
})
.catch((e) => {
console.log('error inside catch:', e.message)
cb(null, null, e)
})
}
console.log(login((data, response, err) => console.log('data', data, 'response', response, 'error', err)))
So, I have to return all these values, but I can return just data. If I change this: https://jsonplaceholder.typicode.com/todos/1 to this: https://j123sonplaceholder.typicode.com/todos/1, to return err, I get undefined. The same issue is with response.
Question: How to get all these values?
data. trycb(null, null, errorObject)to pass an error