deno.land / x / err@0.0.2 / main_example.ts
1234567891011121314151617181920212223242526272829303132333435import 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); } }})();
Version Info
External Dependencies