exupero / saveSvgAsPng

Save SVGs as PNGs from the browser.
MIT License
1.09k stars 362 forks source link

How to handle error ? #211

Open ritwickdey opened 5 years ago

ritwickdey commented 5 years ago

There can be lot of reason for exception. (One example https://github.com/exupero/saveSvgAsPng/issues/199)

But I don't any way to handle error. A typical callback looks like cb(err, data). But in here the callback is cb(data) and if the function throws any error, I can't put any try..catch block as it's a callback operation. (async)

ritwickdey commented 5 years ago

I not sure is this related https://github.com/exupero/saveSvgAsPng/pull/205 or not.

ritwickdey commented 5 years ago

May be this tag will help

https://github.com/exupero/saveSvgAsPng/commit/79b2e640d424c6e16e18a772094ea1dda88e2ad4?diff=split

exupero commented 5 years ago

If the function you're calling returns a promise, you can attach an error-handling callback using the promise's .catch() method. If the function you're calling doesn't return a promise, I'll update it.