Files
api/packages/unraid-shared/src/util/processing.ts
Pujit Mehrotra 7bc583b186 fix: remote access lifecycle during boot & shutdown (#1422)
## Summary

- **New Features**
- Introduced a comprehensive Nginx control script for Unraid OS,
enabling advanced server management, SSL certificate handling, and
dynamic configuration based on system state.
https://github.com/unraid/webgui/pull/2269
- Added a utility function to safely execute code with error handling
support.

- **Improvements**
- Enhanced logging across remote access, WAN access, and settings
services for improved traceability.
- Added initialization and cleanup hooks to remote access and UPnP
services for better lifecycle management.
- Optimized configuration persistence by batching rapid changes for more
efficient updates.
- Refined URL resolution logic for improved configuration retrieval and
error handling.
  - Broadened pattern matching for domain keys in Nginx state parsing.
- Updated remote access settings to reload the network stack after
changes.
- Simplified remote access and WAN port configuration logic for clarity
and accuracy.
- Improved port mapping logic with explicit error handling in UPnP
service.
- Updated UI and form controls for remote access settings to reflect SSL
requirements and access type restrictions.

- **Configuration**
  - Updated the default path for module configuration files.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2025-06-24 15:10:07 -04:00

34 lines
904 B
TypeScript

// Utils related to processing operations
// e.g. parallel processing, safe processing, etc.
/**
* Creates a function that runs a given function and catches any errors.
* If an error is caught, it is passed to the `onError` function.
*
* @param onError - The function to call if an error is caught.
* @returns A function that runs the given function and catches any errors.
* @example
* const errors: Error[] = [];
* const doSafely = makeSafeRunner((error) => {
* if (error instanceof Error) {
* errors.push(error);
* } else {
* this.logger.warn(error, 'Uncaught error in network resolver');
* }
* });
*
* doSafely(() => {
* JSON.parse(aFile);
* throw new Error('test');
* });
*/
export function makeSafeRunner(onError: (error: unknown) => void) {
return <T>(fn: () => T) => {
try {
return fn();
} catch (error) {
onError(error);
}
};
}