deno.land / x / err@0.0.2 / main_example.ts

main_example.ts
نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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); } }})();
err

Version Info

Tagged at
3 years ago

External Dependencies

No external dependencies 🎉