scott.mebberson.codes

JavaScript

JavaScript

Promises

Promise executor pattern

Use the promise executor pattern to ensure errors are automatically captured and the promise rejected, without requiring additional try/catch blocks.

Could be better written with the promise executor pattern to avoid multiple points of error handling.

Consider refactoring functions that use Promise.resolve() (with or without a try/catch block).

The error is automatically captured and the promise rejected, producing a single point for error handling and improving code readability.

Promise catch-error pattern

Use the promise catch-error pattern to receive an [error, result] tuple removing the need for try/catch blocks.

The error is automatically captured and the promise rejected, producing a single point for error handling and improving code readability.