handleError.ts 699 B

1234567891011121314151617181920212223242526272829
  1. import type Uppy from '@uppy/core'
  2. const handleError =
  3. (uppy: Uppy<any, any>) =>
  4. (error: Error): void => {
  5. // authError just means we're not authenticated, don't report it
  6. if ((error as any).isAuthError) {
  7. return
  8. }
  9. // AbortError means the user has clicked "cancel" on an operation
  10. if (error.name === 'AbortError') {
  11. uppy.log('Aborting request', 'warning')
  12. return
  13. }
  14. uppy.log(error, 'error')
  15. if (error.name === 'UserFacingApiError') {
  16. uppy.info(
  17. {
  18. message: uppy.i18n('companionError'),
  19. details: uppy.i18n(error.message),
  20. },
  21. 'warning',
  22. 5000,
  23. )
  24. }
  25. }
  26. export default handleError