小编Dan*_*l M的帖子

安装 cypress - 卡在解压 0% 上

当我跑步时

npm install cypress --save-dev
Run Code Online (Sandbox Code Playgroud)

在 Windows CMD 管理员会话中,我得到以下输出。这已经过夜了,仍然保持在 0%: 输出

如果它很重要,我当前的项目依赖项是

"devDependencies": { "@types/react": "^17.0.0", "@types/react-dom": "^17.0.0", "@types/webpack": "^4.41.25", "@types/react-router-dom": "^5.1.7", "@types/mui-datatables": "^3.7.3", "@types/react-text-mask": "^5.4.7", "@typescript-eslint/eslint-plugin": "^4.17.0", "@typescript-eslint/parser": "^4.17.0", "clean-webpack-plugin": "^3.0.0", "css-loader": "^5.0.1", "eslint": "^7.21.0", "eslint-config-prettier": "^8.1.0", "eslint-plugin-react": "^7.22.0", "eslint-plugin-react-hooks": "^4.2.0", "eslint-webpack-plugin": "^2.5.2", "html-webpack-plugin": "^4.5.0", "husky": "^4.3.8", "lint-staged": "^10.5.4", "prettier": "2.2.1", "style-loader": "^2.0.0", "ts-loader": "^8.0.11", "typescript": "^4.1.2", "url-loader": "^4.1.1", "webpack": "^5.9.0", "webpack-cli": "^4.2.0", "webpack-dev-server": "^3.11.0", "webpack-merge": "^5.4.0" }, 
"dependencies": { "@date-io/dayjs": "^1.3.13", "@fontsource/roboto": "^4.2.2", "@material-ui/core": "^4.11.2", "@material-ui/icons": "^4.11.2", "@material-ui/lab": "^4.0.0-alpha.57", …
Run Code Online (Sandbox Code Playgroud)

node.js npm reactjs npm-install cypress

2
推荐指数
1
解决办法
6975
查看次数

如何在catch子句中访问axios错误响应对象?

我最近升级到 axios 0.23.0,现在在尝试访问 catch 子句中的错误响应对象时收到错误。这是我收到错误的地方:

  const loginUser = async (userData: UserPayload): Promise<void> => {
    try {
      const result = await login(userData);
      const { token } = result.data;
      localStorage.setItem('jwtTokenTS', token);
      setupAxios(token);
      const decoded: User = jwt_decode(token);
      setUser(decoded);
      setAuthenticated(true);
    } catch (err) {
      if (err.response.status === 404) {
        window.alert('User not found');
      } else if (err.response.status === 401) {
        window.alert('Incorrect password');
      } else {
        console.error(err);
      }
    }
  };
Run Code Online (Sandbox Code Playgroud)

第 3 行的“登录”功能是我的 axios 请求,如下所示:

export async function login(user: UserPayload): Promise<AxiosResponse<{ token: string }>> { …
Run Code Online (Sandbox Code Playgroud)

try-catch typescript reactjs axios

2
推荐指数
1
解决办法
3353
查看次数

标签 统计

reactjs ×2

axios ×1

cypress ×1

node.js ×1

npm ×1

npm-install ×1

try-catch ×1

typescript ×1