From a0233c29e587b0999932508cd37e7da63c18ee5d Mon Sep 17 00:00:00 2001 From: xiang <1984871009@qq.com> Date: Sat, 6 May 2023 11:34:37 +0800 Subject: [PATCH] fix: crash --- model/you/index.ts | 6 +++--- utils/index.ts | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/model/you/index.ts b/model/you/index.ts index d3bce7b..ceb3407 100644 --- a/model/you/index.ts +++ b/model/you/index.ts @@ -4,7 +4,7 @@ import UserAgent from 'user-agents'; import tlsClient from 'tls-client'; import {Session} from "tls-client/dist/esm/sessions"; import {Params} from "tls-client/dist/esm/types"; -import {toEventCB, toEventStream} from "../../utils"; +import {parseJSON, toEventCB, toEventStream} from "../../utils"; import {Chat, ChatOptions, Request, Response, ResponseStream} from "../base"; const userAgent = new UserAgent(); @@ -127,14 +127,14 @@ export class You extends Chat { let obj: any; switch (eventName) { case 'youChatToken': - obj = JSON.parse(data) as any; + obj = parseJSON(data,{}) as any; res.text += obj.youChatToken; break; case 'done': resolve(res); return; default: - obj = JSON.parse(data) as any; + obj = parseJSON(data,{}) as any; res.other[eventName] = obj; return; } diff --git a/utils/index.ts b/utils/index.ts index 668c576..8b2523a 100644 --- a/utils/index.ts +++ b/utils/index.ts @@ -36,6 +36,7 @@ export function parseJSON(str: string, defaultObj: any): any | undefined { try { return JSON.parse(str) } catch (e) { + console.error(str,e); return defaultObj; } }