Module

x/err/main_example.ts

simple payload wrapper around Error
Latest
File
import Err, { PAYLOAD } from "./mod.ts";
(async function example_without_err([foo, bar] = ["hello", "world"]) { try { let err = new Error("I just ran into a problem.");
function some_shitty_middleware(err: Error) { // @ts-ignore err.payload = { status: 500., }; }
// @ts-ignore err.payload = { foo, bar }; some_shitty_middleware(err);
throw err; } catch (err) { if (err.hasOwnProperty(PAYLOAD)) { console.error("I found this payload.", (err as Err).payload); } }})();
(async function example_with_err([foo, bar] = ["hello", "world"]) { try { throw new Err("I just ran into a problem.").with({ foo, bar }); } catch (err) { if (err.hasOwnProperty(PAYLOAD)) { console.error("I found this payload.", (err as Err).payload); } }})();