react-native-image-resizer icon indicating copy to clipboard operation
react-native-image-resizer copied to clipboard

fix: don't throw outside promise creation

Open pke opened this issue 3 years ago • 0 comments

When a function returns a promise all its error handling should result in promise rejections.

For instance this could would have an exception thrown when not using await and proper try...catch blocks:

// on iOS
createResizedImage(..., "webp").catch(console.error.bind(console))

This would not print the error but instead throw an exception up the chain.

With the changes in this commit proper exception handling is taken care of.

Both of this works now:

// on iOS
createResizedImage(..., "webp").catch(console.error.bind(console))
// or
try {
  await createResizedImage(..., "webp")
} catch(error) {
  console.error(error)  
}

pke avatar Mar 20 '21 19:03 pke