MCPcopy Create free account
hub / github.com/GoogleCloudPlatform/functions-framework-nodejs / register

Method register

src/invoker.ts:93–128  ·  view source on GitHub ↗

* Registers handlers for uncaught exceptions and other unhandled errors.

()

Source from the content-addressed store, hash-verified

91 * Registers handlers for uncaught exceptions and other unhandled errors.
92 */
93 register() {
94 process.on('uncaughtException', err => {
95 console.error('Uncaught exception');
96 sendCrashResponse({err, res: latestRes, callback: killInstance});
97 });
98
99 process.on('unhandledRejection', err => {
100 console.error('Unhandled rejection');
101 sendCrashResponse({err, res: latestRes, callback: killInstance});
102 });
103
104 process.on('exit', (code: number | string) => {
105 if (typeof code === 'string') {
106 code = parseInt(code);
107 }
108 sendCrashResponse({
109 err: new Error(`Process exited with code ${code}`),
110 res: latestRes,
111 silent: code === 0,
112 });
113 });
114
115 ['SIGINT', 'SIGTERM'].forEach(signal => {
116 process.on(signal as NodeJS.Signals, () => {
117 sendCrashResponse({
118 err: new Error(`Received ${signal}`),
119 res: latestRes,
120 silent: true,
121 callback: () => {
122 // eslint-disable-next-line no-process-exit
123 process.exit();
124 },
125 });
126 });
127 });
128 }
129}

Callers 1

mainFunction · 0.95

Calls 1

sendCrashResponseFunction · 0.90

Tested by

no test coverage detected