Skip to content

Commit

Permalink
add error types
Browse files Browse the repository at this point in the history
  • Loading branch information
binarykitchen committed Nov 23, 2024
1 parent 144071a commit 46a7c74
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 28 deletions.
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import VideomailClient from "./client";
import { FullVideomailErrorData, VideomailErrorData } from "./types/error";
import VideomailEvents from "./types/events";
import { PartialVideomailClientOptions } from "./types/options";
import RecordingStats from "./types/RecordingStats";
Expand All @@ -10,3 +11,4 @@ export type { VideomailEvents };
export type { PartialVideomailClientOptions };
export type { RecordingStats };
export { VideoType, VideomailClient };
export type { VideomailErrorData, FullVideomailErrorData };
47 changes: 25 additions & 22 deletions src/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Response from "superagent/lib/node/response";
import VideomailError from "./util/error/VideomailError";
import { FormInputs, FormMethod } from "./wrappers/form";
import HTTPError from "./util/error/HTTPError";
import { FullVideomailErrorData } from "./types/error";

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

try {
const fullVideomailErrorData: FullVideomailErrorData = {
browser: err.browser,
code: err.code,
cookie: err.cookie,
cpu: err.cpu,
device: err.device,
engine: err.engine,
err: err.err,
explanation: err.explanation,
location: err.location,
logLines: err.logLines,
orientation: err.orientation,
os: err.os,
promise: err.promise,
reason: err.reason,
screen: err.screen,
siteName: err.siteName,
status: err.status,
title: err.title,
message: err.message,
stack: err.stack,
};

await superagent(FormMethod.POST, url)
.query(queryParams)
.set("Timezone-Id", this.timezoneId)
// Note you cant send the Error instance itself, it has to be a plain JSON
.send({
browser: err.browser,
code: err.code,
cookies: err.cookies,
cpu: err.cpu,
device: err.device,
engine: err.engine,
err: err.err,
explanation: err.explanation,
location: err.location,
logLines: err.logLines,
orientation: err.orientation,
os: err.os,
promise: err.promise,
reason: err.reason,
screen: err.screen,
siteName: err.siteName,
status: err.status,
title: err.title,
message: err.message,
stack: err.stack,
})
.send(fullVideomailErrorData)
.timeout(this.options.timeouts.connection);
} catch (exc) {
// Can't throw it again, so just print and do nothing else further.
Expand Down
40 changes: 40 additions & 0 deletions src/types/error.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import type { IBrowser, ICPU, IDevice, IEngine, IOS } from "ua-parser-js";

export interface VideomailErrorData {
cause?: any;
err?: Error | undefined;
explanation?: string | undefined;
logLines?: string[] | undefined;
message: string;
promise?: Promise<any> | undefined;
reason?: any;
siteName?: string | undefined;
title: string;
trace?: string | undefined;
code?: string | undefined;
status?: number | undefined;
stack?: string | undefined;

// These are weird and probably not needed but help with narrowing down issues
// They come mostly from Videomail's proprietary UI code
errConstraint?: string | undefined;
errConstructorName?: string | undefined;
errName?: string | undefined;
errNo?: number | undefined;
errType?: string | undefined;
errTarget?: EventTarget | null;
event?: Event | undefined;
eventStringified?: string | undefined;
}

export interface FullVideomailErrorData extends VideomailErrorData {
browser: IBrowser;
cookie?: string | undefined;
cpu?: ICPU | undefined;
device?: IDevice | undefined;
engine: IEngine;
location: string;
orientation?: string | undefined;
os?: IOS | undefined;
screen: string;
}
12 changes: 6 additions & 6 deletions src/util/error/VideomailError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ class VideomailError extends HTTPError {
public explanation: string | undefined;
public logLines?: string[] | undefined;
public siteName: string | undefined;
public cookies: string | undefined;
public cookie: string | undefined;
public err?: Error | undefined;
public promise?: Promise<any> | undefined;
public reason?: any;
public browser: IBrowser | undefined;
public browser: IBrowser;
public cpu?: ICPU | undefined;
public device?: IDevice | undefined;
public engine?: IEngine | undefined;
public engine: IEngine;
public os?: IOS | undefined;
public screen?: string | undefined;
public screen: string;
public orientation?: string | undefined;

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

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

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

Expand Down

0 comments on commit 46a7c74

Please sign in to comment.