所有承诺的自定义`catch`

时间:2018-09-30 01:07:04

标签: javascript

假设我具有以下功能

const _error_handler = err => {
    console.log('[%s] %s - %s - %s', err.method.toUpperCase(), err.url, err.statusCode, err.statusMessage)
}

我希望我的所有诺言都能够自动实现,因为这是个大难题。所以不要做

promise1
   .then(...)
   .catch(_error_handler)

promise2
   .then(...)
   .catch(_error_handler)

我希望.catch(_error_handler)是隐式的。这可能吗?

0 个答案:

没有答案