finally
方法用于指定不管Promise
对象最后状态如何,都会执行的操作。它接受一个普通的回调函数作为参数,该函数不管怎样都会执行。
<!doctype html>
<html>
<head>
</head>
<body>
<script>
const fetchRequest = (url) => {
return new Promise(async (resolve, reject) => {
let response = await fetch(url);
if (response.status === 200) {
let responseJson = await response.json();
resolve(responseJson);
} else {
reject(new Error('出错了'));
...