API 不可用时重定向到错误页面

Redirect to an error page when API is unavailable

我想在我的 GraphQL API 关闭时重定向到错误页面,而不是显示一个空页面,因为内容无法加载。

我想我必须在 Apollo 收到错误 503 作为回复时进行重定向,但我不知道该怎么做。

谢谢!

您可以在您的 apollo 查询中用这个来处理错误。

 apollo: {
    todos: {
      query: GET_MY_TODOS,
      error(error) {
      console.log(error)
      this.$router.push('/db-error-page')
     }
    },
  },