diff --git a/runtimes/nodejs/src/handler/invoke.ts b/runtimes/nodejs/src/handler/invoke.ts index e0589bfb93..735d5a3be4 100644 --- a/runtimes/nodejs/src/handler/invoke.ts +++ b/runtimes/nodejs/src/handler/invoke.ts @@ -12,7 +12,7 @@ import { FunctionDebugExecutor, } from '../support/engine' import pako from 'pako' -import { base64ToUint8Array, uint8ArrayToBase64 } from '../support/utils' +import { base64ToUint8Array, isObject, uint8ArrayToBase64 } from '../support/utils' export async function handleInvokeFunction(req: IRequest, res: Response) { const name = req.params?.name @@ -90,7 +90,7 @@ async function invokeFunction( // reject request if interceptor return false if ( - typeof result.data === 'object' && + isObject(result.data) && result.data.__type__ === '__interceptor__' && result.data.__res__ == false ) { @@ -200,7 +200,7 @@ async function invokeDebug( // reject request if interceptor return false if ( - typeof result.data === 'object' && + isObject(result.data) && result.data.__type__ === '__interceptor__' && result.data.__res__ == false ) { diff --git a/runtimes/nodejs/src/support/engine/console.ts b/runtimes/nodejs/src/support/engine/console.ts index d9739c89df..a629b1742b 100644 --- a/runtimes/nodejs/src/support/engine/console.ts +++ b/runtimes/nodejs/src/support/engine/console.ts @@ -2,6 +2,7 @@ import * as util from 'util' import chalk from 'chalk' import { padStart } from 'lodash' import Config from '../../config' +import { isObject } from '../utils' enum LogLevel { DEBUG = 'DEBUG', @@ -31,7 +32,7 @@ export class Console { let content = params .map((param) => { if (typeof param === 'string') return this._colorize(level, param) - if (typeof param === 'object') { + if (isObject(param)) { return this._colorize( level, util.inspect(param, { depth: Config.LOG_DEPTH, colors: true }), diff --git a/runtimes/nodejs/src/support/utils.ts b/runtimes/nodejs/src/support/utils.ts index 6fddd7cfbf..a771b04542 100644 --- a/runtimes/nodejs/src/support/utils.ts +++ b/runtimes/nodejs/src/support/utils.ts @@ -68,7 +68,7 @@ export function deepFreeze(object: Object) { for (const name of propNames) { const value = object[name] - if (value && typeof value === 'object') { + if (isObject(value)) { deepFreeze(value) } } @@ -114,4 +114,13 @@ export function uint8ArrayToBase64(buffer: Uint8Array) { export function base64ToUint8Array(base64: string) { const buffer = Buffer.from(base64, 'base64') return new Uint8Array(buffer) -} \ No newline at end of file +} + +/** + * is object. + * @param obj + * @returns + */ +export function isObject(obj: unknown): obj is Object { + return obj !== null && typeof obj === 'object' +}