Skip to content

Latest commit

 

History

History
28 lines (27 loc) · 620 Bytes

errorHandling1.md

File metadata and controls

28 lines (27 loc) · 620 Bytes

不要忽视被拒绝的promise

Bad logo

	getdata()
	  .then(data => {
	    functionThatMightThrow(data);
	  })
	  .catch(error => {
	    console.log(error);
	  });

Good logo

	getdata()
	  .then(data => {
	    functionThatMightThrow(data);
	  })
	  .catch(error => {
	    // One option (more noisy than console.log):
	    console.error(error);
	    // Another option:
	    notifyUserOfError(error);
	    // Another option:
	    reportErrorToService(error);
	    // OR do all three!
	  });