> Can you spot the problem with this piece of code?
Sure. There's no error handling :-)
(Also, if it's not some magic fetch, the return value needs to be json-ed.)
Sure. There's no error handling :-)
(Also, if it's not some magic fetch, the return value needs to be json-ed.)
Also, how should the function handle errors? It's not immediately obvious. An empty array is not the correct thing to return (an empty array could be a valid return value). Returning undefined/null would be another option, but that hides the error from the caller (which might be interested in the exact error message, to be able to properly deal with it).
try { ... } catch (e) { throw “an unknown error occurred” }
;)
"What's wrong with this code? It tries to make `async` look more readable by skipping the ugly try/catch block/s" ;)