Rocky_Mountain_Vending/.pnpm-store/v10/files/b3/8afc58204ec686ae9e67fda3a14231239dbbe1be441252bcf07d5e4cc832ef8345f560602e81b745068a082a498b0a0471aa60308ae533610b05d444862d9b
DMleadgen 46d973904b
Initial commit: Rocky Mountain Vending website
Next.js website for Rocky Mountain Vending company featuring:
- Product catalog with Stripe integration
- Service areas and parts pages
- Admin dashboard with Clerk authentication
- SEO optimized pages with JSON-LD structured data

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-12 16:22:15 -07:00

62 lines
1.7 KiB
Text

Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
const is = require('./is.js');
/**
* Wrap a callback function with error handling.
* If an error is thrown, it will be passed to the `onError` callback and re-thrown.
*
* If the return value of the function is a promise, it will be handled with `maybeHandlePromiseRejection`.
*
* If an `onFinally` callback is provided, this will be called when the callback has finished
* - so if it returns a promise, once the promise resolved/rejected,
* else once the callback has finished executing.
* The `onFinally` callback will _always_ be called, no matter if an error was thrown or not.
*/
function handleCallbackErrors
(fn, onError, onFinally = () => {}) {
let maybePromiseResult;
try {
maybePromiseResult = fn();
} catch (e) {
onError(e);
onFinally();
throw e;
}
return maybeHandlePromiseRejection(maybePromiseResult, onError, onFinally);
}
/**
* Maybe handle a promise rejection.
* This expects to be given a value that _may_ be a promise, or any other value.
* If it is a promise, and it rejects, it will call the `onError` callback.
* Other than this, it will generally return the given value as-is.
*/
function maybeHandlePromiseRejection(
value,
onError,
onFinally,
) {
if (is.isThenable(value)) {
// @ts-expect-error - the isThenable check returns the "wrong" type here
return value.then(
res => {
onFinally();
return res;
},
e => {
onError(e);
onFinally();
throw e;
},
);
}
onFinally();
return value;
}
exports.handleCallbackErrors = handleCallbackErrors;
//# sourceMappingURL=handleCallbackErrors.js.map