From 46a7c74ced3fe68c30ad15cd21a1c1da1ab456d0 Mon Sep 17 00:00:00 2001 From: Michael Heuberger Date: Sun, 24 Nov 2024 11:37:24 +1300 Subject: [PATCH] add error types --- src/index.ts | 2 ++ src/resource.ts | 47 +++++++++++++++++--------------- src/types/error.ts | 40 +++++++++++++++++++++++++++ src/util/error/VideomailError.ts | 12 ++++---- 4 files changed, 73 insertions(+), 28 deletions(-) create mode 100644 src/types/error.ts diff --git a/src/index.ts b/src/index.ts index de5f53ef..3d75b670 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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"; @@ -10,3 +11,4 @@ export type { VideomailEvents }; export type { PartialVideomailClientOptions }; export type { RecordingStats }; export { VideoType, VideomailClient }; +export type { VideomailErrorData, FullVideomailErrorData }; diff --git a/src/resource.ts b/src/resource.ts index b29ab933..90f62f8a 100644 --- a/src/resource.ts +++ b/src/resource.ts @@ -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) { @@ -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. diff --git a/src/types/error.ts b/src/types/error.ts new file mode 100644 index 00000000..f6bbc693 --- /dev/null +++ b/src/types/error.ts @@ -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 | 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; +} diff --git a/src/util/error/VideomailError.ts b/src/util/error/VideomailError.ts index e242d09b..5cadee19 100644 --- a/src/util/error/VideomailError.ts +++ b/src/util/error/VideomailError.ts @@ -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 | 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; @@ -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("×");