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
const mock = (success, timeout) => { | |
return new Promise((resolve, reject) => { | |
setTimeout(() => { | |
if(success) { | |
resolve(); | |
} else { | |
reject({message: 'Error'}); | |
} | |
}, timeout); | |
}); |
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
const handleErrors = (res: Response) => { | |
if (!res.ok) { | |
throw Error(res.statusText); | |
} | |
return res; | |
} | |
fetch("http://httpstat.us/500") | |
.then(handleErrors) |
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
const filterObj = (obj, f) => (o=Object).fromEntries(o.entries(obj).filter([k,v]=>f(k))) | |
const select = (obj, ...props) => filterObj(obj, k => props.includes(k)) | |
const omit = (obj, ...props) => filterObj(obj, k => !props.includes(k)) |