What dark magic is this
Last active
November 10, 2018 19:57
-
-
Save hew/b22360097f4606ebce6f19df917ea0f2 to your computer and use it in GitHub Desktop.
What dark magic is this
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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