У меня проблема с обещаниями.Мне чрезвычайно трудно различить тип ошибки, от которой я хотел бы вылететь, и ошибку, которую я хочу обработать.
Вот как я думаю, что я должен решить эти типы ошибок, но я хотел бы знать, если это элегантный способ сделать это.
PromiseA //I believe that any errors thrown in this function will crash node
.catch(function( {throw custom_err(msg)}))
//Here I can catch any rejected promises which I believe will always be
//operational errors and then I can flag them as such.
//The error is then thrown to the final catch which handles it appropriately
.then(function() { return Function1().catch(throw custom_err(msg)); })
//Now if an error is thrown by Function1 inside a then statement it will
//fall down the chain. It will then be caught by the final catch and it will not be flagged
//as operational. My final catch will throw it and crash node which I desire.
//However if it is operational Function1 will reject the promise and it will be caught by
//the nested catch which then flags it appropriately and throws to the final catch
.catch(finalErrorHandler);
Работает ли это решение?Правильно ли я согласен с моими предположениями о потоке отказов и бросков?
Правильно ли я считаю, что если в библиотеке, которую я использую (например, Function1()
), выдается ошибка (например, *1008*),скорее всего ошибка программиста?
Это элегантный способ решения проблемы?Есть ли более очевидное решение, которого мне не хватает?