const apiserver = new Promise((resolve, reject) => { const user = { name: "tanishq dhingra", age: 19, }; const status = 200; if (status === 200) { resolve(user); } else { reject("some error occurred here"); } }); apiserver .then((result) => { console.log(result); }) .catch((err) => { console.log(err); // shows actual error message });
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter