Skip to content

Commit

Permalink
fix: crash
Browse files Browse the repository at this point in the history
  • Loading branch information
xiangsx committed May 6, 2023
1 parent 0e5211c commit a0233c2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
6 changes: 3 additions & 3 deletions model/you/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit a0233c2

Please sign in to comment.