PanJiaChen/vue-admin-template · error · Error

new Error(res.message || 'Error')

Error message

new Error(res.message || 'Error')

What it means

Rejection error created in the response interceptor after a non-20000 business code was already surfaced via Message; it propagates the server's 'message' (or the 'Error' sentinel when absent) to the caller's .catch so the promise chain does not silently treat the failed response as success.

Source

Thrown at src/utils/request.js:69

        message: res.message || 'Error',
        type: 'error',
        duration: 5 * 1000
      })

      // 50008: Illegal token; 50012: Other clients logged in; 50014: Token expired;
      if (res.code === 50008 || res.code === 50012 || res.code === 50014) {
        // to re-login
        MessageBox.confirm('You have been logged out, you can cancel to stay on this page, or log in again', 'Confirm logout', {
          confirmButtonText: 'Re-Login',
          cancelButtonText: 'Cancel',
          type: 'warning'
        }).then(() => {
          store.dispatch('user/resetToken').then(() => {
            location.reload()
          })
        })
      }
      return Promise.reject(new Error(res.message || 'Error'))
    } else {
      return res
    }
  },
  error => {
    console.log('err' + error) // for debug
    Message({
      message: error.message,
      type: 'error',
      duration: 5 * 1000
    })
    return Promise.reject(error)
  }
)

export default service

View on GitHub (pinned to 4c18a3f47b)

Solutions

  1. Catch the rejection in the calling code and handle the specific business error code
  2. Have the backend return meaningful 'message' values so the propagated Error is informative
  3. Centralize handling of auth codes (50008/50012/50014) to avoid duplicate handling at call sites
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at src/utils/request.js:69 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of PanJiaChen/vue-admin-template@4c18a3f47b (2026-09-02). Data as JSON: /api/errors/45d092b74d0ecf8b. Report an issue: GitHub.