MCPcopy Create free account
hub / github.com/hydro-dev/Hydro / Err

Function Err

framework/framework/error.ts:23–44  ·  view source on GitHub ↗
(name: string, Class: IHydroError, ...info: Array<(() => string) | string | number>)

Source from the content-addressed store, hash-verified

21}
22
23const Err = (name: string, Class: IHydroError, ...info: Array<(() => string) | string | number>) => {
24 let msg: () => string;
25 let code: number;
26 for (const item of info) {
27 if (typeof item === 'number') {
28 code = item;
29 } else if (typeof item === 'string') {
30 msg = function () { return item; };
31 } else if (typeof item === 'function') {
32 msg = item;
33 }
34 }
35 // eslint-disable-next-line ts/no-shadow
36 return class HydroError extends Class {
37 name = name;
38 constructor(...args: any[]) {
39 super(...args);
40 if (msg) this.msg = msg;
41 if (code) this.code = code;
42 }
43 };
44};
45
46export const UserFacingError = Err('UserFacingError', HydroError, 'UserFacingError', 400);
47export const SystemError = Err('SystemError', HydroError, 'SystemError', 500);

Callers 2

error.tsFile · 0.85
error.tsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected