JakubHJ
Reactiflux4y ago
3 replies
JakubH

venus – 14-43 Oct 11

Hi is it possible to get rid of promise functions that throws error from
promise.all
array response?
My solution kinda sucks cuz I am returning
null
on error and then removing it from array.

Can you think of any better approach?

const serversPromise = servers.map(async ({ ip, port }) =>
  getShortServerQuery(ip, port).catch(() => null)
);

// serversData: (Servertype | null)[]
let serversData = await Promise.all(serversPromise);

// My solution
serversData = serversData.filter((res) => res != null);
Was this page helpful?