|
1 | 1 | import { LogLevel, MessageType } from '../enums'; |
2 | | -import { Config, Log } from '../types'; |
| 2 | +import { Config, LogMessageData } from '../types'; |
| 3 | +import { parseError } from '../utils'; |
3 | 4 | import { Connection } from './connection'; |
4 | 5 |
|
5 | 6 | export class Kaiware { |
@@ -44,39 +45,21 @@ export class Kaiware { |
44 | 45 | const stringifiedData: string[] = data.map((a) => { |
45 | 46 | if (typeof a === 'string') { |
46 | 47 | return a; |
47 | | - } else if (a instanceof Error) { |
48 | | - return JSON.stringify(a, [ |
49 | | - 'message', |
50 | | - 'type', |
51 | | - 'name', |
52 | | - 'stack', |
53 | | - 'fileName', |
54 | | - 'lineNumber', |
55 | | - 'columnNumber' |
56 | | - ]); |
57 | | - } else if (a instanceof ErrorEvent) { |
58 | | - return JSON.stringify(a, [ |
59 | | - 'message', |
60 | | - 'type', |
61 | | - 'name', |
62 | | - 'stack', |
63 | | - 'fileName', |
64 | | - 'lineNumber', |
65 | | - 'columnNumber' |
66 | | - ]); |
| 48 | + } else if (a instanceof Error || a instanceof ErrorEvent) { |
| 49 | + return JSON.stringify(parseError(a)); |
67 | 50 | } else { |
68 | 51 | return JSON.stringify(a); |
69 | 52 | } |
70 | 53 | }); |
71 | 54 |
|
72 | | - const log: Omit<Log, 'id'> = { |
| 55 | + const log: LogMessageData = { |
73 | 56 | source: this.config!.sourceId, |
74 | 57 | level: level, |
75 | 58 | data: stringifiedData, |
76 | 59 | timestamp: new Date().toISOString() |
77 | 60 | }; |
78 | 61 |
|
79 | | - this.connection.sendMessage(MessageType.NewLog, log); |
| 62 | + this.connection.sendMessage<LogMessageData>(MessageType.NewLog, log); |
80 | 63 | } |
81 | 64 |
|
82 | 65 | static log = { |
|
0 commit comments