Skip to content

Instantly share code, notes, and snippets.

@hew
Last active November 10, 2018 19:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hew/b22360097f4606ebce6f19df917ea0f2 to your computer and use it in GitHub Desktop.
Save hew/b22360097f4606ebce6f19df917ea0f2 to your computer and use it in GitHub Desktop.
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