I saw a piece of code that looks funny to me. It feels like there are multiple things wrong here. Am I seeing a ternary here returning an error rather than a value? Shouldn't this therefore be an if-else?
const aData = await response.json();
return await new Promise((resolve, reject) => {
(aData.title === aName)
? resolve('A data was found')
: reject(new Error('Incorrect data was returned'));
});
Both
resolveandrejectjust return the valueundefined, and your callback function doesn'treturnanything at all. Using a ternary operator to make it a single expression is rather useless.For clarity, you should better write
although really you shouldn't be using the
new Promiseconstructor here at all. Just