I have a simple function, which looks similar to the following
const foo = (bar) => {
return ![val1, val2].includes(bar) ? await apiRequest :
await apiRequest + await apiRequest2
}
apiRequest returns a number.
This function is surrounded by a function which handles errors for many functions.
However for this specific function, I don't just want to return an error to the user in the case of one of the apiRequests failing in the second part of the ternary.
const foo = (bar) => {
return ![val1, val2].includes(bar) ? await apiRequest :
await apiRequest + await apiRequest2
// intended logic for second part of ternary
if apiRequest and apiRequest resolve, return apiRequest + apiRequest2
if apiRequest fails, return apiRequest2
if apiRequest 2 fails, return apiRequest
}
I'm not exactly sure of the way I should be going about this. Perhaps I could surround each part with try and catch, and in the catch statement I could then try the next part of the logic?
I feel like I will end up with a super messy function in this case