3.2.0 • Published 2 years ago

default-error-handler-promise v3.2.0

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

when i use axios, i am confused about error handler, because i want to process axios error unified, for example pop up error message, but i some page, i want to process the axios error with different type, in that case, i do not know how to do.

so i publish the package to solve axios error with balanceing handling unified error and special error.

The usage is as follows, take axios interceptors for example

axios.interceptors.response.use(
  (response) => {
    const {
      data,
      data: { code }
    } = response
    if (code !== 200) {
      // if you do not process the error, the error will procesed as print
      return new DefaultErrorHandlerPromise(
        Promise.reject(response, () => console.log('错误将会被统一输出'))
      )
    }
    return data
  },
  (err) => {
    return new DefaultErrorHandlerPromise(
      Promise.reject(response, () => console.log('错误将会被统一输出'))
    )
  }
)

when you request, if you will not process the error specially, you should code as follow

axios('xxxxx').then(() => {})

if you want to process the error specially, you should code as follow

axios('xxxx').then(() => {}).catch(error => {
  // process the error specially
})

about Promise.all and Promise.race, you can use DefaultErrorHandlerPromise.all and DefaultErrorHandlerPromise.race as follows

DefaultErrorHandlerPromise.all(
  [promise1, promise2], 
  defaultErrorHandler /*defaultErrorHandler*/ ).then(() => {}
)

DefaultErrorHandlerPromise.race(
  [promise1, promise2], 
  defaultErrorHandler /*defaultErrorHandler*/ ).then(() => {}
)

if you want to process erros specially, you can do as follows

DefaultErrorHandlerPromise.all(
  [promise1, promise2], 
  defaultErrorHandler /*defaultErrorHandler*/ 
).then(() => {}).catch(error => {
  // process the error specially
})

DefaultErrorHandlerPromise.all(
  [promise1, promise2], 
  defaultErrorHandler /*defaultErrorHandler*/ 
).then(() => {}).catch(error => {
  // process the error specially
})
3.2.0

2 years ago

3.1.0

2 years ago

3.0.0

2 years ago

2.5.0

2 years ago

2.4.0

2 years ago

2.3.2

2 years ago

2.3.1

2 years ago

2.3.0

2 years ago

2.2.0

2 years ago

2.1.0

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.0.0

2 years ago