Skip to content

Commit 21ba0eb

Browse files
committed
add new HTTPError class
1 parent e872284 commit 21ba0eb

File tree

5 files changed

+35
-3
lines changed

5 files changed

+35
-3
lines changed

etc/release-it.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ const config: Config = {
55
// github: {
66
// release: true,
77
// }
8+
// https://github.com/release-it/release-it/tree/main?tab=readme-ov-file#hooks
9+
hooks: {
10+
"before:init": [
11+
"npm run prettier",
12+
"npm run lint",
13+
"npm run types:check",
14+
"npm test",
15+
],
16+
"after:bump": "npm run build:prod",
17+
},
818
};
919

1020
export default config;

src/resource.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import createError from "./util/error/createError";
77
import Response from "superagent/lib/node/response";
88
import VideomailError from "./util/error/VideomailError";
99
import { FormInputs, FormMethod } from "./wrappers/form";
10+
import HTTPError from "./util/error/HTTPError";
1011

1112
function findOriginalExc(exc: unknown) {
1213
if (exc instanceof Error && "response" in exc) {
@@ -17,7 +18,7 @@ function findOriginalExc(exc: unknown) {
1718
const message = body.error.message as string;
1819
const cause = body.error.cause;
1920

20-
const error = new Error(message, { cause });
21+
const error = new HTTPError(message, { cause });
2122

2223
if (body.error.name) {
2324
error.name = body.error.name;
@@ -27,6 +28,14 @@ function findOriginalExc(exc: unknown) {
2728
error.stack = body.error.stack;
2829
}
2930

31+
if (body.error.status) {
32+
error.status = body.error.status;
33+
}
34+
35+
if (body.error.code) {
36+
error.code = body.error.code;
37+
}
38+
3039
return error;
3140
}
3241
}

src/util/error/HTTPError.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class HTTPError extends Error {
2+
public code?: string | undefined;
3+
public status?: number | undefined;
4+
}
5+
6+
export default HTTPError;

src/util/error/VideomailError.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import { IBrowser, ICPU, IDevice, IEngine, IOS } from "ua-parser-js";
22
import { VideomailClientOptions } from "../../types/options";
33
import getBrowser from "../getBrowser";
4+
import HTTPError from "./HTTPError";
45

56
export interface ErrData extends ErrorOptions {
67
explanation: string | undefined;
78
logLines?: string[] | undefined;
89
err?: Error | undefined;
910
}
1011

11-
class VideomailError extends Error {
12+
class VideomailError extends HTTPError {
1213
public readonly title = "videomail-client error";
1314
public readonly location = window.location.href;
1415

src/util/error/createError.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ import { isAudioEnabled } from "../options/audio";
55
import VideomailError, { ErrData } from "./VideomailError";
66
import getBrowser from "../getBrowser";
77
import { VideomailClientOptions } from "../../types/options";
8+
import HTTPError from "./HTTPError";
89

910
interface ErrorParams {
10-
err?: Error;
11+
err?: HTTPError;
1112
exc?: unknown;
1213
message?: string;
1314
explanation?: string;
@@ -228,6 +229,11 @@ function createError(errorParams: ErrorParams) {
228229
errData,
229230
);
230231

232+
if (err) {
233+
videomailError.status = err.status;
234+
videomailError.code = err.code;
235+
}
236+
231237
if (options.reportErrors) {
232238
const resource = new Resource(options);
233239

0 commit comments

Comments
 (0)