web_lib

Common web application libraries
git clone https://radroots.dev/git/web_lib.git
Log | Files | Refs | LICENSE

index.ts (634B)


      1 import { IError } from "@radroots/types-bindings";
      2 
      3 export const err_msg = <T extends string>(err: T | IError<T>): IError<T> => {
      4     return typeof err === "string" ? { err } : err;
      5 };
      6 
      7 export const throw_err = (param: string | IError<string>): never => {
      8     if (typeof param === `string`) throw new Error(param);
      9     else throw new Error(param.err);
     10 };
     11 
     12 export const handle_err = (e: unknown, append?: string): IError<string> => {
     13     console.log(`[handle_err] `, e, append || "");
     14     const msg = (e as Error).message ? (e as Error).message : String(e);
     15     const err = `${msg}${append ? ` ${append}` : ``}`;
     16     return { err };
     17 };