@ngx-maintenance/utils
TypeScript icon, indicating that this package has built-in type declarations

0.1.1 • Public • Published

utils

Helper functions for node http and our try catch function

export async function tryCatch<T, E extends Error>(
	mainOperation: () => Promise<T> | T
): Promise<{ error?: E; result?: T }> {
	try {
		const result = await Promise.resolve(mainOperation());
		return { result };
	} catch (error) {
		if (error instanceof Error) {
			return { error: error as E };
		}
		console.error("Caught an unexpected error type:", error);
		return { error: new Error("An unexpected error occurred") as E };
	}
}

Readme

Keywords

none

Package Sidebar

Install

npm i @ngx-maintenance/utils

Weekly Downloads

0

Version

0.1.1

License

none

Unpacked Size

7.05 kB

Total Files

12

Last publish

Collaborators

  • jordan-hall
  • danielglejzner