Log errors in __DEV__ mode (Fix #905)

This commit is contained in:
Niklas von Hertzen 2017-08-04 00:13:20 +08:00
parent 9a7075252b
commit 3977ebeadd
2 changed files with 19 additions and 1 deletions

View File

@ -17,4 +17,14 @@ export default class Logger {
[Date.now() - this.start + 'ms', 'html2canvas:'].concat([].slice.call(args, 0))
);
}
// eslint-disable-next-line flowtype/no-weak-types
error(...args: any) {
Function.prototype.bind
.call(window.console.error, window.console)
.apply(
window.console,
[Date.now() - this.start + 'ms', 'html2canvas:'].concat([].slice.call(args, 0))
);
}
}

View File

@ -51,7 +51,7 @@ const html2canvas = (element: HTMLElement, config: Options): Promise<HTMLCanvasE
return Promise.reject(__DEV__ ? `Invalid canvas element provided in options` : '');
}
return cloneWindow(
const result = cloneWindow(
ownerDocument,
ownerDocument,
windowBounds,
@ -102,6 +102,14 @@ const html2canvas = (element: HTMLElement, config: Options): Promise<HTMLCanvasE
return renderer.render(stack);
});
});
if (__DEV__) {
return result.catch(e => {
logger.error(e);
throw e;
});
}
return result;
};
module.exports = html2canvas;