move this function in a final `.catch()` so that we also catch possible errors sent by the call to "close"