exceptions thrown in plugins are now properly caught in libresilientFetch (ref. #36)

master^2
Michał 'rysiek' Woźniak 2024-02-28 06:47:02 +00:00
rodzic 81dfaab7c5
commit 0932bf9b9f
1 zmienionych plików z 48 dodań i 41 usunięć

Wyświetl plik

@ -1026,6 +1026,10 @@ let initFromRequest = (req) => {
* reqInfo - instance of LibResilientResourceInfo
*/
let libresilientFetch = (plugin, url, init, reqInfo) => {
// we really need to catch any exceptions here
// otherwise other plugins will not run!
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch#gotchas_when_throwing_errors
try {
// status of the plugin
reqInfo.update({
method: (plugin && "name" in plugin) ? plugin.name : "unknown",
@ -1068,6 +1072,9 @@ let libresilientFetch = (plugin, url, init, reqInfo) => {
fetch_promise,
timeout_promise
]);
} catch(e) {
return Promise.reject(e)
}
}