finalizeResult()

in core/nodejsActionBase/runner.js [114:143]


    finalizeResult(result, resolve) {
        // Non-promises/undefined instantly resolve.
        Promise.resolve(result).then(resolvedResult => {
            // This happens, e.g. if you just have "return;"
            if (typeof resolvedResult === "undefined") {
                resolvedResult = {};
            }
            resolve(resolvedResult);
        }).catch(error => {
            // A rejected Promise from the user code maps into a
            // successful promise wrapping a whisk-encoded error.

            // Special case if the user just called "reject()".
            if (!error) {
                resolve({error: {}});
            } else {
                // Replace unsupported require statement with
                // dynamically import npm serialize-error package returning a promise
                import('serialize-error')
                .then(module => {
                    // if serialize-error is imported correctly the function resolves with a serializedError
                    resolve({error: module.serializeError(error)});
                })
                .catch(err => {
                    // When there is an error to serialize the error object, resolve with the error message
                    resolve({error: err.message });
                });
            }
        });
    }