-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathErrorTests.mjs
76 lines (69 loc) · 1.79 KB
/
ErrorTests.mjs
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Generated by ReScript, PLEASE EDIT WITH CARE
import * as Test from "./Test.mjs";
import * as Js_exn from "rescript/lib/es6/js_exn.js";
import * as Caml_option from "rescript/lib/es6/caml_option.js";
import * as RescriptCore from "../src/RescriptCore.mjs";
import * as Caml_js_exceptions from "rescript/lib/es6/caml_js_exceptions.js";
function panicTest(param) {
var caught;
try {
caught = RescriptCore.panic("uh oh");
}
catch (raw_err){
var err = Caml_js_exceptions.internalToOCamlException(raw_err);
if (err.RE_EXN_ID === Js_exn.$$Error) {
caught = err._1.message;
} else {
throw err;
}
}
Test.run([
[
"ErrorTests.res",
8,
22,
43
],
"Should resolve test"
], caught, (function (prim0, prim1) {
return prim0 === prim1;
}), "Panic! uh oh");
}
panicTest(undefined);
function catchCustomError(param) {
var authenticationError = new Error("authentication error");
var codeCaught;
authenticationError["code"] = "invalid-password";
try {
throw authenticationError;
}
catch (raw_exn){
var exn = Caml_js_exceptions.internalToOCamlException(raw_exn);
var err = Caml_js_exceptions.as_js_exn(exn);
if (err !== undefined) {
var code = Caml_option.valFromOption(err)["code"];
if (code !== undefined) {
codeCaught = Caml_option.valFromOption(code);
}
} else {
throw exn;
}
}
Test.run([
[
"ErrorTests.res",
34,
15,
39
],
"Can access custom code"
], codeCaught, (function (prim0, prim1) {
return prim0 === prim1;
}), "invalid-password");
}
catchCustomError(undefined);
export {
panicTest ,
catchCustomError ,
}
/* Not a pure module */