fix(xen-api/putResource): fix a number of issues

- hide `VDI_IO_ERROR` when using content-length hack
- avoid unhandled rejection in case upload fails
This commit is contained in:
Julien Fontanet 2023-01-23 17:59:33 +01:00
parent 4bf81ac33b
commit 2f65a86aa0
2 changed files with 22 additions and 11 deletions

View File

@ -30,5 +30,6 @@
<!--packages-start-->
- @xen-orchestra/backups patch
- xen-api patch
<!--packages-end-->

View File

@ -520,24 +520,34 @@ export class Xapi extends EventEmitter {
)
if (pTaskResult !== undefined) {
pTaskResult = pTaskResult.catch(error => {
error.url = response.url
throw error
})
}
if (useHack) {
// In case of the hack, ignore (but log) the very probably `VDI_IO_ERROR` because it is usually irrelevant
pTaskResult = pTaskResult.catch(error => {
console.warn(this._humanId, 'Xapi#putResource', pathname, error)
})
} else {
pTaskResult = pTaskResult.catch(error => {
error.url = response.url
throw error
})
if (!useHack) {
// consume the response
response.resume()
return pTaskResult
// avoid unhandled rejection in case the upload fails
pTaskResult.catch(noop)
}
}
const { req } = response
if (!req.finished) {
await fromEvents(req, ['close', 'finish'])
}
response.cancel()
if (useHack) {
response.cancel()
} else {
// consume the response
response.resume()
}
return pTaskResult
}