makeMightFailSync
You also have the option to make your own mightFailSync
wrapper function. Pass in any sync function to makeMightFailSync
and it will return a mightFailSync
wrapper function for you to use.
function parseJSON(jsonString: string) {
return JSON.parse(jsonString); // This might throw
}
const mightParseJSON = makeMightFailSync(parseJSON);
const [error, result] = mightParseJSON("");
if (error) {
console.error("Parsing failed:", error);
return;
}
console.log("Parsed object:", result);
function parseJSON(jsonString: string) {
return JSON.parse(jsonString); // This might throw
}
const mightParseJSON = makeMightFailSync(parseJSON);
const [error, result] = mightParseJSON("");
if (error) {
console.error("Parsing failed:", error);
return;
}
console.log("Parsed object:", result);
function parseJSON(jsonString: string) {
return JSON.parse(jsonString); // This might throw
}
const mightParseJSON = makeMightFailSync(parseJSON);
const [error, result] = mightParseJSON("");
if (error) {
console.error("Parsing failed:", error);
return;
}
console.log("Parsed object:", result);
function parseJSON(jsonString: string) {
return JSON.parse(jsonString); // This might throw
}
const mightParseJSON = makeMightFailSync(parseJSON);
const [error, result] = mightParseJSON("");
if (error) {
console.error("Parsing failed:", error);
return;
}
console.log("Parsed object:", result);