Skip to content

Instantly share code, notes, and snippets.

@hew
Last active Nov 10, 2018
Embed
What would you like to do?
What dark magic is this

What dark magic is this

let jsErrorToExn = jsError => {
let isObject = rawObj =>
Js.typeof(rawObj) == "object"
&& !Js.Array.isArray(rawObj)
&& !((Obj.magic(rawObj): Js.null('a)) === Js.null);
let couldBeError = rawObj => {
let obj: {
.
"name": string,
"message": string,
} =
Obj.magic(rawObj);
!((Obj.magic(obj##message): Js.undefined('a)) === Js.undefined)
&& !((Obj.magic(obj##name): Js.undefined('a)) === Js.undefined);
/* && Js.String.includes("SomethingSpecific", obj##name); */
};
isObject(jsError) ?
couldBeError(jsError) ?
Some(Js.Exn.internalToOCamlException(Obj.magic(jsError): Obj.t)) :
None :
None;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment