Quickly apply the data request interface, how to use finally?

problem description

in fast application development, use Promise method. In view of the complete situation, using finally does not work properly. Consult some materials to know that the fast application official specification does not support finally, so how to solve this problem?

related codes

import fetch from "@system.fetch"

fetch.fetch({
  url: params.url,
  method: params.method,
  data: params.data
})
.then(response => {
  // ....
})
.catch((error, code) => {
  console.log(`request fail, code = ${code}`)
})
.finally(() => {
  // ?
})

did not add / es-shims/Promise.prototype.finally


for cases where finally cannot be used, it can be solved by polyfill, which is also applicable in fast applications. There are many existing methods, and a relatively simple one is introduced. The code is as follows:


Promiseresolvereject2

function fetchData(){
    fetch.fetch({
      url: params.url,
      method: params.method,
      data: params.data
    })
    .then(response => {
      // success
      return Promise.resolve(response);
    })
    .catch((error, code) => {
      console.log(`request fail, code = ${code}`);
      // err
      return Promise.reject(error);
    })
}

then call to execute the code you want in finally regardless of success or failure

fetchData().then(res => {
    // when success
    // do final
}).catch(err => {
    // when error
    // do final
})
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e5fcfb-4584d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e5fcfb-4584d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?