From 26d61af90263540e1ecc6bfb3c21cd6c2f9e9460 Mon Sep 17 00:00:00 2001 From: Julien Fontanet Date: Wed, 2 Dec 2015 17:32:17 +0100 Subject: [PATCH] Fall back to legacy events on server failure (work around #2). --- packages/xen-api/src/index.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/xen-api/src/index.js b/packages/xen-api/src/index.js index e907051d3..9edd5dac2 100644 --- a/packages/xen-api/src/index.js +++ b/packages/xen-api/src/index.js @@ -413,7 +413,7 @@ export class Xapi extends EventEmitter { error => { // Unwrap error if necessary. if (error instanceof Bluebird.OperationalError) { - ({ error } = error) + error = error.cause } console.error( @@ -552,7 +552,14 @@ export class Xapi extends EventEmitter { ) return loop().catch(error => { - if (isMethodUnknown(error)) { + if ( + isMethodUnknown(error) || + + // If the server failed, it is probably due to an excessively + // large response. + // Falling back to legacy events watch should be enough. + error && error.res.statusCode === 500 + ) { return this._watchEventsLegacy() }