Skip to content

Commit 46a7c74

Browse files
committed
add error types
1 parent 144071a commit 46a7c74

File tree

4 files changed

+73
-28
lines changed

4 files changed

+73
-28
lines changed

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import VideomailClient from "./client";
2+
import { FullVideomailErrorData, VideomailErrorData } from "./types/error";
23
import VideomailEvents from "./types/events";
34
import { PartialVideomailClientOptions } from "./types/options";
45
import RecordingStats from "./types/RecordingStats";
@@ -10,3 +11,4 @@ export type { VideomailEvents };
1011
export type { PartialVideomailClientOptions };
1112
export type { RecordingStats };
1213
export { VideoType, VideomailClient };
14+
export type { VideomailErrorData, FullVideomailErrorData };

src/resource.ts

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import Response from "superagent/lib/node/response";
88
import VideomailError from "./util/error/VideomailError";
99
import { FormInputs, FormMethod } from "./wrappers/form";
1010
import HTTPError from "./util/error/HTTPError";
11+
import { FullVideomailErrorData } from "./types/error";
1112

1213
function findOriginalExc(exc: unknown) {
1314
if (exc instanceof Error && "response" in exc) {
@@ -133,32 +134,34 @@ class Resource {
133134
const url = `${this.options.baseUrl}/client-error/`;
134135

135136
try {
137+
const fullVideomailErrorData: FullVideomailErrorData = {
138+
browser: err.browser,
139+
code: err.code,
140+
cookie: err.cookie,
141+
cpu: err.cpu,
142+
device: err.device,
143+
engine: err.engine,
144+
err: err.err,
145+
explanation: err.explanation,
146+
location: err.location,
147+
logLines: err.logLines,
148+
orientation: err.orientation,
149+
os: err.os,
150+
promise: err.promise,
151+
reason: err.reason,
152+
screen: err.screen,
153+
siteName: err.siteName,
154+
status: err.status,
155+
title: err.title,
156+
message: err.message,
157+
stack: err.stack,
158+
};
159+
136160
await superagent(FormMethod.POST, url)
137161
.query(queryParams)
138162
.set("Timezone-Id", this.timezoneId)
139163
// Note you cant send the Error instance itself, it has to be a plain JSON
140-
.send({
141-
browser: err.browser,
142-
code: err.code,
143-
cookies: err.cookies,
144-
cpu: err.cpu,
145-
device: err.device,
146-
engine: err.engine,
147-
err: err.err,
148-
explanation: err.explanation,
149-
location: err.location,
150-
logLines: err.logLines,
151-
orientation: err.orientation,
152-
os: err.os,
153-
promise: err.promise,
154-
reason: err.reason,
155-
screen: err.screen,
156-
siteName: err.siteName,
157-
status: err.status,
158-
title: err.title,
159-
message: err.message,
160-
stack: err.stack,
161-
})
164+
.send(fullVideomailErrorData)
162165
.timeout(this.options.timeouts.connection);
163166
} catch (exc) {
164167
// Can't throw it again, so just print and do nothing else further.

src/types/error.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import type { IBrowser, ICPU, IDevice, IEngine, IOS } from "ua-parser-js";
2+
3+
export interface VideomailErrorData {
4+
cause?: any;
5+
err?: Error | undefined;
6+
explanation?: string | undefined;
7+
logLines?: string[] | undefined;
8+
message: string;
9+
promise?: Promise<any> | undefined;
10+
reason?: any;
11+
siteName?: string | undefined;
12+
title: string;
13+
trace?: string | undefined;
14+
code?: string | undefined;
15+
status?: number | undefined;
16+
stack?: string | undefined;
17+
18+
// These are weird and probably not needed but help with narrowing down issues
19+
// They come mostly from Videomail's proprietary UI code
20+
errConstraint?: string | undefined;
21+
errConstructorName?: string | undefined;
22+
errName?: string | undefined;
23+
errNo?: number | undefined;
24+
errType?: string | undefined;
25+
errTarget?: EventTarget | null;
26+
event?: Event | undefined;
27+
eventStringified?: string | undefined;
28+
}
29+
30+
export interface FullVideomailErrorData extends VideomailErrorData {
31+
browser: IBrowser;
32+
cookie?: string | undefined;
33+
cpu?: ICPU | undefined;
34+
device?: IDevice | undefined;
35+
engine: IEngine;
36+
location: string;
37+
orientation?: string | undefined;
38+
os?: IOS | undefined;
39+
screen: string;
40+
}

src/util/error/VideomailError.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@ class VideomailError extends HTTPError {
1616
public explanation: string | undefined;
1717
public logLines?: string[] | undefined;
1818
public siteName: string | undefined;
19-
public cookies: string | undefined;
19+
public cookie: string | undefined;
2020
public err?: Error | undefined;
2121
public promise?: Promise<any> | undefined;
2222
public reason?: any;
23-
public browser: IBrowser | undefined;
23+
public browser: IBrowser;
2424
public cpu?: ICPU | undefined;
2525
public device?: IDevice | undefined;
26-
public engine?: IEngine | undefined;
26+
public engine: IEngine;
2727
public os?: IOS | undefined;
28-
public screen?: string | undefined;
28+
public screen: string;
2929
public orientation?: string | undefined;
3030

3131
private readonly classList?: string[] | undefined;
@@ -66,8 +66,8 @@ class VideomailError extends HTTPError {
6666
this.engine = usefulClientData.engine;
6767
this.os = usefulClientData.os;
6868

69-
const cookies = global.document.cookie.split("; ");
70-
this.cookies = cookies.length > 0 ? cookies.join(",\n") : undefined;
69+
const cookie = global.document.cookie.split("; ");
70+
this.cookie = cookie.length > 0 ? cookie.join(",\n") : undefined;
7171

7272
this.screen = [screen.width, screen.height, screen.colorDepth].join("×");
7373

0 commit comments

Comments
 (0)