upgrade axios

This commit is contained in:
Proddy
2022-10-07 20:26:17 +02:00
parent c90be99216
commit 5faffc3886
23 changed files with 116 additions and 109 deletions

View File

@@ -13,14 +13,14 @@
"@msgpack/msgpack": "^2.8.0", "@msgpack/msgpack": "^2.8.0",
"@mui/icons-material": "^5.10.6", "@mui/icons-material": "^5.10.6",
"@mui/material": "^5.10.8", "@mui/material": "^5.10.8",
"@table-library/react-table-library": "4.0.18", "@table-library/react-table-library": "4.0.23",
"@types/lodash": "^4.14.186", "@types/lodash": "^4.14.186",
"@types/node": "^18.8.2", "@types/node": "^18.8.3",
"@types/react": "^18.0.21", "@types/react": "^18.0.21",
"@types/react-dom": "^18.0.6", "@types/react-dom": "^18.0.6",
"@types/react-router-dom": "^5.3.3", "@types/react-router-dom": "^5.3.3",
"async-validator": "^4.2.5", "async-validator": "^4.2.5",
"axios": "^0.27.2", "axios": "^1.1.2",
"http-proxy-middleware": "^2.0.6", "http-proxy-middleware": "^2.0.6",
"jwt-decode": "^3.1.2", "jwt-decode": "^3.1.2",
"lodash": "^4.17.21", "lodash": "^4.17.21",
@@ -31,7 +31,7 @@
"react-dom": "^18.2.0", "react-dom": "^18.2.0",
"react-dropzone": "^14.2.2", "react-dropzone": "^14.2.2",
"react-icons": "^4.4.0", "react-icons": "^4.4.0",
"react-router-dom": "^6.4.1", "react-router-dom": "^6.4.2",
"react-scripts": "5.0.1", "react-scripts": "5.0.1",
"sockette": "^2.0.6", "sockette": "^2.0.6",
"typesafe-i18n": "^5.14.0", "typesafe-i18n": "^5.14.0",
@@ -3470,9 +3470,9 @@
} }
}, },
"node_modules/@remix-run/router": { "node_modules/@remix-run/router": {
"version": "1.0.1", "version": "1.0.2",
"resolved": "https://registry.npmjs.org/@remix-run/router/-/router-1.0.1.tgz", "resolved": "https://registry.npmjs.org/@remix-run/router/-/router-1.0.2.tgz",
"integrity": "sha512-eBV5rvW4dRFOU1eajN7FmYxjAIVz/mRHgUE9En9mBn6m3mulK3WTR5C3iQhL9MZ14rWAq+xOlEaCkDiW0/heOg==", "integrity": "sha512-GRSOFhJzjGN+d4sKHTMSvNeUPoZiDHWmRnXfzaxrqe7dE/Nzlc8BiMSJdLDESZlndM7jIUrZ/F4yWqVYlI0rwQ==",
"engines": { "engines": {
"node": ">=14" "node": ">=14"
} }
@@ -3796,9 +3796,9 @@
} }
}, },
"node_modules/@table-library/react-table-library": { "node_modules/@table-library/react-table-library": {
"version": "4.0.18", "version": "4.0.23",
"resolved": "https://registry.npmjs.org/@table-library/react-table-library/-/react-table-library-4.0.18.tgz", "resolved": "https://registry.npmjs.org/@table-library/react-table-library/-/react-table-library-4.0.23.tgz",
"integrity": "sha512-3GX5712YuWPFeUilr8UG22SCNR9BylD5Y4xPF+pHhb1QM7WXw6SLgpeGq6UDTQGOtmKtKtwKGWXdkmvVDg8pkA==", "integrity": "sha512-o2L/fqhwQNxsNbbm3LIiyZzEwaTslhG1tY9ArkYdS0xJyRhJxcOLfbJ3+dcnOOn+aIJpmPmQH+gr7RYJC0P8uw==",
"dependencies": { "dependencies": {
"clsx": "1.1.1", "clsx": "1.1.1",
"react-virtualized-auto-sizer": "1.0.6", "react-virtualized-auto-sizer": "1.0.6",
@@ -4029,9 +4029,9 @@
"integrity": "sha512-Y4XFY5VJAuw0FgAqPNd6NNoV44jbq9Bz2L7Rh/J6jLTiHBSBJa9fxqQIvkIld4GsoDOcCbvzOUAbLPsSKKg+uA==" "integrity": "sha512-Y4XFY5VJAuw0FgAqPNd6NNoV44jbq9Bz2L7Rh/J6jLTiHBSBJa9fxqQIvkIld4GsoDOcCbvzOUAbLPsSKKg+uA=="
}, },
"node_modules/@types/node": { "node_modules/@types/node": {
"version": "18.8.2", "version": "18.8.3",
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.8.2.tgz", "resolved": "https://registry.npmjs.org/@types/node/-/node-18.8.3.tgz",
"integrity": "sha512-cRMwIgdDN43GO4xMWAfJAecYn8wV4JbsOGHNfNUIDiuYkUYAR5ec4Rj7IO2SAhFPEfpPtLtUTbbny/TCT7aDwA==" "integrity": "sha512-0os9vz6BpGwxGe9LOhgP/ncvYN5Tx1fNcd2TM3rD/aCGBkysb+ZWpXEocG24h6ZzOi13+VB8HndAQFezsSOw1w=="
}, },
"node_modules/@types/parse-json": { "node_modules/@types/parse-json": {
"version": "4.0.0", "version": "4.0.0",
@@ -5008,12 +5008,13 @@
} }
}, },
"node_modules/axios": { "node_modules/axios": {
"version": "0.27.2", "version": "1.1.2",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.27.2.tgz", "resolved": "https://registry.npmjs.org/axios/-/axios-1.1.2.tgz",
"integrity": "sha512-t+yRIyySRTp/wua5xEr+z1q60QmLq8ABsS5O9Me1AsE5dfKqgnCFzwiCZZ/cGNd1lq4/7akDWMxdhVlucjmnOQ==", "integrity": "sha512-bznQyETwElsXl2RK7HLLwb5GPpOLlycxHCtrpDR/4RqqBzjARaOTo3jz4IgtntWUYee7Ne4S8UHd92VCuzPaWA==",
"dependencies": { "dependencies": {
"follow-redirects": "^1.14.9", "follow-redirects": "^1.15.0",
"form-data": "^4.0.0" "form-data": "^4.0.0",
"proxy-from-env": "^1.1.0"
} }
}, },
"node_modules/axobject-query": { "node_modules/axobject-query": {
@@ -14147,6 +14148,11 @@
"node": ">= 0.10" "node": ">= 0.10"
} }
}, },
"node_modules/proxy-from-env": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz",
"integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg=="
},
"node_modules/psl": { "node_modules/psl": {
"version": "1.9.0", "version": "1.9.0",
"resolved": "https://registry.npmjs.org/psl/-/psl-1.9.0.tgz", "resolved": "https://registry.npmjs.org/psl/-/psl-1.9.0.tgz",
@@ -14545,11 +14551,11 @@
} }
}, },
"node_modules/react-router": { "node_modules/react-router": {
"version": "6.4.1", "version": "6.4.2",
"resolved": "https://registry.npmjs.org/react-router/-/react-router-6.4.1.tgz", "resolved": "https://registry.npmjs.org/react-router/-/react-router-6.4.2.tgz",
"integrity": "sha512-OJASKp5AykDWFewgWUim1vlLr7yfD4vO/h+bSgcP/ix8Md+LMHuAjovA74MQfsfhQJGGN1nHRhwS5qQQbbBt3A==", "integrity": "sha512-Rb0BAX9KHhVzT1OKhMvCDMw776aTYM0DtkxqUBP8dNBom3mPXlfNs76JNGK8wKJ1IZEY1+WGj+cvZxHVk/GiKw==",
"dependencies": { "dependencies": {
"@remix-run/router": "1.0.1" "@remix-run/router": "1.0.2"
}, },
"engines": { "engines": {
"node": ">=14" "node": ">=14"
@@ -14559,12 +14565,12 @@
} }
}, },
"node_modules/react-router-dom": { "node_modules/react-router-dom": {
"version": "6.4.1", "version": "6.4.2",
"resolved": "https://registry.npmjs.org/react-router-dom/-/react-router-dom-6.4.1.tgz", "resolved": "https://registry.npmjs.org/react-router-dom/-/react-router-dom-6.4.2.tgz",
"integrity": "sha512-MY7NJCrGNVJtGp8ODMOBHu20UaIkmwD2V3YsAOUQoCXFk7Ppdwf55RdcGyrSj+ycSL9Uiwrb3gTLYSnzcRoXww==", "integrity": "sha512-yM1kjoTkpfjgczPrcyWrp+OuQMyB1WleICiiGfstnQYo/S8hPEEnVjr/RdmlH6yKK4Tnj1UGXFSa7uwAtmDoLQ==",
"dependencies": { "dependencies": {
"@remix-run/router": "1.0.1", "@remix-run/router": "1.0.2",
"react-router": "6.4.1" "react-router": "6.4.2"
}, },
"engines": { "engines": {
"node": ">=14" "node": ">=14"
@@ -19819,9 +19825,9 @@
"integrity": "sha512-50/17A98tWUfQ176raKiOGXuYpLyyVMkxxG6oylzL3BPOlA6ADGdK7EYunSa4I064xerltq9TGXs8HmOk5E+vw==" "integrity": "sha512-50/17A98tWUfQ176raKiOGXuYpLyyVMkxxG6oylzL3BPOlA6ADGdK7EYunSa4I064xerltq9TGXs8HmOk5E+vw=="
}, },
"@remix-run/router": { "@remix-run/router": {
"version": "1.0.1", "version": "1.0.2",
"resolved": "https://registry.npmjs.org/@remix-run/router/-/router-1.0.1.tgz", "resolved": "https://registry.npmjs.org/@remix-run/router/-/router-1.0.2.tgz",
"integrity": "sha512-eBV5rvW4dRFOU1eajN7FmYxjAIVz/mRHgUE9En9mBn6m3mulK3WTR5C3iQhL9MZ14rWAq+xOlEaCkDiW0/heOg==" "integrity": "sha512-GRSOFhJzjGN+d4sKHTMSvNeUPoZiDHWmRnXfzaxrqe7dE/Nzlc8BiMSJdLDESZlndM7jIUrZ/F4yWqVYlI0rwQ=="
}, },
"@rollup/plugin-babel": { "@rollup/plugin-babel": {
"version": "5.3.1", "version": "5.3.1",
@@ -20018,9 +20024,9 @@
} }
}, },
"@table-library/react-table-library": { "@table-library/react-table-library": {
"version": "4.0.18", "version": "4.0.23",
"resolved": "https://registry.npmjs.org/@table-library/react-table-library/-/react-table-library-4.0.18.tgz", "resolved": "https://registry.npmjs.org/@table-library/react-table-library/-/react-table-library-4.0.23.tgz",
"integrity": "sha512-3GX5712YuWPFeUilr8UG22SCNR9BylD5Y4xPF+pHhb1QM7WXw6SLgpeGq6UDTQGOtmKtKtwKGWXdkmvVDg8pkA==", "integrity": "sha512-o2L/fqhwQNxsNbbm3LIiyZzEwaTslhG1tY9ArkYdS0xJyRhJxcOLfbJ3+dcnOOn+aIJpmPmQH+gr7RYJC0P8uw==",
"requires": { "requires": {
"clsx": "1.1.1", "clsx": "1.1.1",
"react-virtualized-auto-sizer": "1.0.6", "react-virtualized-auto-sizer": "1.0.6",
@@ -20233,9 +20239,9 @@
"integrity": "sha512-Y4XFY5VJAuw0FgAqPNd6NNoV44jbq9Bz2L7Rh/J6jLTiHBSBJa9fxqQIvkIld4GsoDOcCbvzOUAbLPsSKKg+uA==" "integrity": "sha512-Y4XFY5VJAuw0FgAqPNd6NNoV44jbq9Bz2L7Rh/J6jLTiHBSBJa9fxqQIvkIld4GsoDOcCbvzOUAbLPsSKKg+uA=="
}, },
"@types/node": { "@types/node": {
"version": "18.8.2", "version": "18.8.3",
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.8.2.tgz", "resolved": "https://registry.npmjs.org/@types/node/-/node-18.8.3.tgz",
"integrity": "sha512-cRMwIgdDN43GO4xMWAfJAecYn8wV4JbsOGHNfNUIDiuYkUYAR5ec4Rj7IO2SAhFPEfpPtLtUTbbny/TCT7aDwA==" "integrity": "sha512-0os9vz6BpGwxGe9LOhgP/ncvYN5Tx1fNcd2TM3rD/aCGBkysb+ZWpXEocG24h6ZzOi13+VB8HndAQFezsSOw1w=="
}, },
"@types/parse-json": { "@types/parse-json": {
"version": "4.0.0", "version": "4.0.0",
@@ -20973,12 +20979,13 @@
"integrity": "sha512-32+ub6kkdhhWick/UjvEwRchgoetXqTK14INLqbGm5U2TzBkBNF3nQtLYm8ovxSkQWArjEQvftCKryjZaATu3w==" "integrity": "sha512-32+ub6kkdhhWick/UjvEwRchgoetXqTK14INLqbGm5U2TzBkBNF3nQtLYm8ovxSkQWArjEQvftCKryjZaATu3w=="
}, },
"axios": { "axios": {
"version": "0.27.2", "version": "1.1.2",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.27.2.tgz", "resolved": "https://registry.npmjs.org/axios/-/axios-1.1.2.tgz",
"integrity": "sha512-t+yRIyySRTp/wua5xEr+z1q60QmLq8ABsS5O9Me1AsE5dfKqgnCFzwiCZZ/cGNd1lq4/7akDWMxdhVlucjmnOQ==", "integrity": "sha512-bznQyETwElsXl2RK7HLLwb5GPpOLlycxHCtrpDR/4RqqBzjARaOTo3jz4IgtntWUYee7Ne4S8UHd92VCuzPaWA==",
"requires": { "requires": {
"follow-redirects": "^1.14.9", "follow-redirects": "^1.15.0",
"form-data": "^4.0.0" "form-data": "^4.0.0",
"proxy-from-env": "^1.1.0"
} }
}, },
"axobject-query": { "axobject-query": {
@@ -27407,6 +27414,11 @@
} }
} }
}, },
"proxy-from-env": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz",
"integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg=="
},
"psl": { "psl": {
"version": "1.9.0", "version": "1.9.0",
"resolved": "https://registry.npmjs.org/psl/-/psl-1.9.0.tgz", "resolved": "https://registry.npmjs.org/psl/-/psl-1.9.0.tgz",
@@ -27692,20 +27704,20 @@
"integrity": "sha512-F27qZr8uUqwhWZboondsPx8tnC3Ct3SxZA3V5WyEvujRyyNv0VYPhoBg1gZ8/MV5tubQp76Trw8lTv9hzRBa+A==" "integrity": "sha512-F27qZr8uUqwhWZboondsPx8tnC3Ct3SxZA3V5WyEvujRyyNv0VYPhoBg1gZ8/MV5tubQp76Trw8lTv9hzRBa+A=="
}, },
"react-router": { "react-router": {
"version": "6.4.1", "version": "6.4.2",
"resolved": "https://registry.npmjs.org/react-router/-/react-router-6.4.1.tgz", "resolved": "https://registry.npmjs.org/react-router/-/react-router-6.4.2.tgz",
"integrity": "sha512-OJASKp5AykDWFewgWUim1vlLr7yfD4vO/h+bSgcP/ix8Md+LMHuAjovA74MQfsfhQJGGN1nHRhwS5qQQbbBt3A==", "integrity": "sha512-Rb0BAX9KHhVzT1OKhMvCDMw776aTYM0DtkxqUBP8dNBom3mPXlfNs76JNGK8wKJ1IZEY1+WGj+cvZxHVk/GiKw==",
"requires": { "requires": {
"@remix-run/router": "1.0.1" "@remix-run/router": "1.0.2"
} }
}, },
"react-router-dom": { "react-router-dom": {
"version": "6.4.1", "version": "6.4.2",
"resolved": "https://registry.npmjs.org/react-router-dom/-/react-router-dom-6.4.1.tgz", "resolved": "https://registry.npmjs.org/react-router-dom/-/react-router-dom-6.4.2.tgz",
"integrity": "sha512-MY7NJCrGNVJtGp8ODMOBHu20UaIkmwD2V3YsAOUQoCXFk7Ppdwf55RdcGyrSj+ycSL9Uiwrb3gTLYSnzcRoXww==", "integrity": "sha512-yM1kjoTkpfjgczPrcyWrp+OuQMyB1WleICiiGfstnQYo/S8hPEEnVjr/RdmlH6yKK4Tnj1UGXFSa7uwAtmDoLQ==",
"requires": { "requires": {
"@remix-run/router": "1.0.1", "@remix-run/router": "1.0.2",
"react-router": "6.4.1" "react-router": "6.4.2"
} }
}, },
"react-scripts": { "react-scripts": {

View File

@@ -9,14 +9,14 @@
"@msgpack/msgpack": "^2.8.0", "@msgpack/msgpack": "^2.8.0",
"@mui/icons-material": "^5.10.6", "@mui/icons-material": "^5.10.6",
"@mui/material": "^5.10.8", "@mui/material": "^5.10.8",
"@table-library/react-table-library": "4.0.18", "@table-library/react-table-library": "4.0.23",
"@types/lodash": "^4.14.186", "@types/lodash": "^4.14.186",
"@types/node": "^18.8.2", "@types/node": "^18.8.3",
"@types/react": "^18.0.21", "@types/react": "^18.0.21",
"@types/react-dom": "^18.0.6", "@types/react-dom": "^18.0.6",
"@types/react-router-dom": "^5.3.3", "@types/react-router-dom": "^5.3.3",
"async-validator": "^4.2.5", "async-validator": "^4.2.5",
"axios": "^0.27.2", "axios": "^1.1.2",
"http-proxy-middleware": "^2.0.6", "http-proxy-middleware": "^2.0.6",
"jwt-decode": "^3.1.2", "jwt-decode": "^3.1.2",
"lodash": "^4.17.21", "lodash": "^4.17.21",
@@ -27,7 +27,7 @@
"react-dom": "^18.2.0", "react-dom": "^18.2.0",
"react-dropzone": "^14.2.2", "react-dropzone": "^14.2.2",
"react-icons": "^4.4.0", "react-icons": "^4.4.0",
"react-router-dom": "^6.4.1", "react-router-dom": "^6.4.2",
"react-scripts": "5.0.1", "react-scripts": "5.0.1",
"sockette": "^2.0.6", "sockette": "^2.0.6",
"typesafe-i18n": "^5.14.0", "typesafe-i18n": "^5.14.0",

View File

@@ -9,8 +9,6 @@ import * as AuthenticationApi from './api/authentication';
import { PROJECT_NAME } from './api/env'; import { PROJECT_NAME } from './api/env';
import { AuthenticationContext } from './contexts/authentication'; import { AuthenticationContext } from './contexts/authentication';
import { AxiosError } from 'axios';
import { extractErrorMessage, onEnterCallback, updateValue } from './utils'; import { extractErrorMessage, onEnterCallback, updateValue } from './utils';
import { SignInRequest } from './types'; import { SignInRequest } from './types';
import { ValidatedTextField } from './components'; import { ValidatedTextField } from './components';
@@ -56,8 +54,8 @@ const SignIn: FC = () => {
try { try {
const { data: loginResponse } = await AuthenticationApi.signIn(signInRequest); const { data: loginResponse } = await AuthenticationApi.signIn(signInRequest);
authenticationContext.signIn(loginResponse.access_token); authenticationContext.signIn(loginResponse.access_token);
} catch (error: unknown) { } catch (error) {
if (error instanceof AxiosError) { if (error.response) {
if (error.response?.status === 401) { if (error.response?.status === 401) {
enqueueSnackbar(LL.INVALID_LOGIN(), { variant: 'warning' }); enqueueSnackbar(LL.INVALID_LOGIN(), { variant: 'warning' });
} }

View File

@@ -1,4 +1,4 @@
import axios, { AxiosPromise, CancelToken } from 'axios'; import axios, { AxiosPromise, CancelToken, AxiosProgressEvent } from 'axios';
import { decode } from '@msgpack/msgpack'; import { decode } from '@msgpack/msgpack';
@@ -89,7 +89,7 @@ function calculateEventSourceRoot(endpointPath: string) {
export interface FileUploadConfig { export interface FileUploadConfig {
cancelToken?: CancelToken; cancelToken?: CancelToken;
onUploadProgress?: (progressEvent: ProgressEvent) => void; onUploadProgress?: (progressEvent: AxiosProgressEvent) => void;
} }
export const startUploadFile = (url: string, file: File, config?: FileUploadConfig): AxiosPromise<void> => { export const startUploadFile = (url: string, file: File, config?: FileUploadConfig): AxiosPromise<void> => {

View File

@@ -1,6 +1,8 @@
import { FC, Fragment } from 'react'; import { FC, Fragment } from 'react';
import { useDropzone, DropzoneState } from 'react-dropzone'; import { useDropzone, DropzoneState } from 'react-dropzone';
import { AxiosProgressEvent } from 'axios';
import { Box, Button, LinearProgress, Theme, Typography, useTheme } from '@mui/material'; import { Box, Button, LinearProgress, Theme, Typography, useTheme } from '@mui/material';
import CloudUploadIcon from '@mui/icons-material/CloudUpload'; import CloudUploadIcon from '@mui/icons-material/CloudUpload';
@@ -8,8 +10,6 @@ import CancelIcon from '@mui/icons-material/Cancel';
import { useI18nContext } from '../../i18n/i18n-react'; import { useI18nContext } from '../../i18n/i18n-react';
const progressPercentage = (progress: ProgressEvent) => Math.round((progress.loaded * 100) / progress.total);
const getBorderColor = (theme: Theme, props: DropzoneState) => { const getBorderColor = (theme: Theme, props: DropzoneState) => {
if (props.isDragAccept) { if (props.isDragAccept) {
return theme.palette.success.main; return theme.palette.success.main;
@@ -27,7 +27,7 @@ export interface SingleUploadProps {
onDrop: (acceptedFiles: File[]) => void; onDrop: (acceptedFiles: File[]) => void;
onCancel: () => void; onCancel: () => void;
uploading: boolean; uploading: boolean;
progress?: ProgressEvent; progress?: AxiosProgressEvent;
} }
const SingleUpload: FC<SingleUploadProps> = ({ onDrop, onCancel, uploading, progress }) => { const SingleUpload: FC<SingleUploadProps> = ({ onDrop, onCancel, uploading, progress }) => {
@@ -47,8 +47,8 @@ const SingleUpload: FC<SingleUploadProps> = ({ onDrop, onCancel, uploading, prog
const progressText = () => { const progressText = () => {
if (uploading) { if (uploading) {
if (progress?.lengthComputable) { if (progress?.total) {
return LL.UPLOADING() + `: ${progressPercentage(progress)}%`; return LL.UPLOADING() + ': ' + Math.round((progress.loaded * 100) / progress.total) + '%';
} }
return LL.UPLOADING() + `\u2026`; return LL.UPLOADING() + `\u2026`;
} }
@@ -80,8 +80,8 @@ const SingleUpload: FC<SingleUploadProps> = ({ onDrop, onCancel, uploading, prog
<Fragment> <Fragment>
<Box width="100%" p={2}> <Box width="100%" p={2}>
<LinearProgress <LinearProgress
variant={!progress || progress.lengthComputable ? 'determinate' : 'indeterminate'} variant={!progress || progress.total ? 'determinate' : 'indeterminate'}
value={!progress ? 0 : progress.lengthComputable ? progressPercentage(progress) : 0} value={!progress ? 0 : progress.total ? Math.round((progress.loaded * 100) / progress.total) : 0}
/> />
</Box> </Box>
<Button startIcon={<CancelIcon />} variant="outlined" color="secondary" onClick={onCancel}> <Button startIcon={<CancelIcon />} variant="outlined" color="secondary" onClick={onCancel}>

View File

@@ -1,5 +1,5 @@
import { useCallback, useEffect, useState } from 'react'; import { useCallback, useEffect, useState } from 'react';
import axios, { AxiosPromise, CancelTokenSource } from 'axios'; import axios, { AxiosPromise, CancelTokenSource, AxiosProgressEvent } from 'axios';
import { useSnackbar } from 'notistack'; import { useSnackbar } from 'notistack';
import { extractErrorMessage } from '../../utils'; import { extractErrorMessage } from '../../utils';
@@ -16,7 +16,7 @@ const useFileUpload = ({ upload }: MediaUploadOptions) => {
const { enqueueSnackbar } = useSnackbar(); const { enqueueSnackbar } = useSnackbar();
const [uploading, setUploading] = useState<boolean>(false); const [uploading, setUploading] = useState<boolean>(false);
const [uploadProgress, setUploadProgress] = useState<ProgressEvent>(); const [uploadProgress, setUploadProgress] = useState<AxiosProgressEvent>();
const [uploadCancelToken, setUploadCancelToken] = useState<CancelTokenSource>(); const [uploadCancelToken, setUploadCancelToken] = useState<CancelTokenSource>();
const resetUploadingStates = () => { const resetUploadingStates = () => {
@@ -47,7 +47,7 @@ const useFileUpload = ({ upload }: MediaUploadOptions) => {
}); });
resetUploadingStates(); resetUploadingStates();
enqueueSnackbar(LL.UPLOAD() + ' ' + LL.SUCCESSFUL(), { variant: 'success' }); enqueueSnackbar(LL.UPLOAD() + ' ' + LL.SUCCESSFUL(), { variant: 'success' });
} catch (error: unknown) { } catch (error) {
if (axios.isCancel(error)) { if (axios.isCancel(error)) {
enqueueSnackbar(LL.UPLOAD() + ' ' + LL.ABORTED(), { variant: 'warning' }); enqueueSnackbar(LL.UPLOAD() + ' ' + LL.ABORTED(), { variant: 'warning' });
} else { } else {

View File

@@ -28,7 +28,7 @@ const Authentication: FC<RequiredChildrenProps> = ({ children }) => {
const decodedMe = AuthenticationApi.decodeMeJWT(accessToken); const decodedMe = AuthenticationApi.decodeMeJWT(accessToken);
setMe(decodedMe); setMe(decodedMe);
enqueueSnackbar(LL.LOGGED_IN({ name: decodedMe.username }), { variant: 'success' }); enqueueSnackbar(LL.LOGGED_IN({ name: decodedMe.username }), { variant: 'success' });
} catch (error: unknown) { } catch (error) {
setMe(undefined); setMe(undefined);
throw new Error('Failed to parse JWT'); throw new Error('Failed to parse JWT');
} }
@@ -54,7 +54,7 @@ const Authentication: FC<RequiredChildrenProps> = ({ children }) => {
await AuthenticationApi.verifyAuthorization(); await AuthenticationApi.verifyAuthorization();
setMe(AuthenticationApi.decodeMeJWT(accessToken)); setMe(AuthenticationApi.decodeMeJWT(accessToken));
setInitialized(true); setInitialized(true);
} catch (error: unknown) { } catch (error) {
setMe(undefined); setMe(undefined);
setInitialized(true); setInitialized(true);
} }

View File

@@ -16,7 +16,7 @@ const FeaturesLoader: FC<RequiredChildrenProps> = (props) => {
try { try {
const response = await FeaturesApi.readFeatures(); const response = await FeaturesApi.readFeatures();
setFeatures(response.data); setFeatures(response.data);
} catch (error: unknown) { } catch (error) {
setErrorMessage(extractErrorMessage(error, 'Failed to fetch application details.')); setErrorMessage(extractErrorMessage(error, 'Failed to fetch application details.'));
} }
}, []); }, []);

View File

@@ -1,8 +1,6 @@
import { useEffect, FC, useState, useCallback, useRef } from 'react'; import { useEffect, FC, useState, useCallback, useRef } from 'react';
import { useSnackbar } from 'notistack'; import { useSnackbar } from 'notistack';
import { AxiosError } from 'axios';
import { Button } from '@mui/material'; import { Button } from '@mui/material';
import PermScanWifiIcon from '@mui/icons-material/PermScanWifi'; import PermScanWifiIcon from '@mui/icons-material/PermScanWifi';
@@ -57,8 +55,8 @@ const WiFiNetworkScanner: FC = () => {
newNetworkList.networks.sort(compareNetworks); newNetworkList.networks.sort(compareNetworks);
setNetworkList(newNetworkList); setNetworkList(newNetworkList);
} }
} catch (error: unknown) { } catch (error) {
if (error instanceof AxiosError) { if (error.response) {
finishedWithError(LL.PROBLEM_LOADING() + ' ' + error.response?.data.message); finishedWithError(LL.PROBLEM_LOADING() + ' ' + error.response?.data.message);
} else { } else {
finishedWithError(LL.PROBLEM_LOADING()); finishedWithError(LL.PROBLEM_LOADING());
@@ -73,8 +71,8 @@ const WiFiNetworkScanner: FC = () => {
try { try {
await NetworkApi.scanNetworks(); await NetworkApi.scanNetworks();
setTimeout(pollNetworkList, POLLING_FREQUENCY); setTimeout(pollNetworkList, POLLING_FREQUENCY);
} catch (error: unknown) { } catch (error) {
if (error instanceof AxiosError) { if (error.response) {
finishedWithError(LL.PROBLEM_LOADING() + ' ' + error.response?.data.message); finishedWithError(LL.PROBLEM_LOADING() + ' ' + error.response?.data.message);
} else { } else {
finishedWithError(LL.PROBLEM_LOADING()); finishedWithError(LL.PROBLEM_LOADING());

View File

@@ -91,7 +91,7 @@ const NTPStatusForm: FC = () => {
enqueueSnackbar(LL.TIME_SET(), { variant: 'success' }); enqueueSnackbar(LL.TIME_SET(), { variant: 'success' });
setSettingTime(false); setSettingTime(false);
loadData(); loadData();
} catch (error: unknown) { } catch (error) {
enqueueSnackbar(extractErrorMessage(error, LL.PROBLEM_UPDATING()), { variant: 'error' }); enqueueSnackbar(extractErrorMessage(error, LL.PROBLEM_UPDATING()), { variant: 'error' });
} finally { } finally {
setProcessing(false); setProcessing(false);

View File

@@ -37,7 +37,7 @@ const GenerateToken: FC<GenerateTokenProps> = ({ username, onClose }) => {
const getToken = useCallback(async () => { const getToken = useCallback(async () => {
try { try {
setToken((await SecurityApi.generateToken(username)).data); setToken((await SecurityApi.generateToken(username)).data);
} catch (error: unknown) { } catch (error) {
enqueueSnackbar(extractErrorMessage(error, LL.PROBLEM_UPDATING()), { variant: 'error' }); enqueueSnackbar(extractErrorMessage(error, LL.PROBLEM_UPDATING()), { variant: 'error' });
} }
}, [username, enqueueSnackbar, LL]); }, [username, enqueueSnackbar, LL]);

View File

@@ -50,7 +50,7 @@ const GeneralFileUpload: FC<UploadFileProps> = ({ uploadGeneralFile }) => {
} else { } else {
saveFile(response.data, 'settings'); saveFile(response.data, 'settings');
} }
} catch (error: unknown) { } catch (error) {
enqueueSnackbar(extractErrorMessage(error, LL.PROBLEM_LOADING()), { variant: 'error' }); enqueueSnackbar(extractErrorMessage(error, LL.PROBLEM_LOADING()), { variant: 'error' });
} }
}; };
@@ -63,7 +63,7 @@ const GeneralFileUpload: FC<UploadFileProps> = ({ uploadGeneralFile }) => {
} else { } else {
saveFile(response.data, 'customizations'); saveFile(response.data, 'customizations');
} }
} catch (error: unknown) { } catch (error) {
enqueueSnackbar(extractErrorMessage(error, LL.PROBLEM_LOADING()), { variant: 'error' }); enqueueSnackbar(extractErrorMessage(error, LL.PROBLEM_LOADING()), { variant: 'error' });
} }
}; };

View File

@@ -21,7 +21,7 @@ const RestartMonitor: FC = () => {
try { try {
await SystemApi.readSystemStatus(POLL_TIMEOUT); await SystemApi.readSystemStatus(POLL_TIMEOUT);
document.location.href = '/fileUpdated'; document.location.href = '/fileUpdated';
} catch (error: unknown) { } catch (error) {
if (new Date().getTime() < timeoutAt.current) { if (new Date().getTime() < timeoutAt.current) {
setTimeoutId(setTimeout(poll.current, POLL_INTERVAL)); setTimeoutId(setTimeout(poll.current, POLL_INTERVAL));
} else { } else {

View File

@@ -111,7 +111,7 @@ const SystemLog: FC = () => {
if (response.status !== 200) { if (response.status !== 200) {
enqueueSnackbar(LL.PROBLEM_UPDATING(), { variant: 'error' }); enqueueSnackbar(LL.PROBLEM_UPDATING(), { variant: 'error' });
} }
} catch (error: unknown) { } catch (error) {
enqueueSnackbar(extractErrorMessage(error, LL.PROBLEM_UPDATING()), { variant: 'error' }); enqueueSnackbar(extractErrorMessage(error, LL.PROBLEM_UPDATING()), { variant: 'error' });
} }
} }
@@ -163,7 +163,7 @@ const SystemLog: FC = () => {
const fetchLog = useCallback(async () => { const fetchLog = useCallback(async () => {
try { try {
setLogEntries((await SystemApi.readLogEntries()).data); setLogEntries((await SystemApi.readLogEntries()).data);
} catch (error: unknown) { } catch (error) {
setErrorMessage(extractErrorMessage(error, LL.PROBLEM_LOADING())); setErrorMessage(extractErrorMessage(error, LL.PROBLEM_LOADING()));
} }
}, [LL]); }, [LL]);

View File

@@ -86,7 +86,7 @@ const SystemStatusForm: FC = () => {
try { try {
await SystemApi.restart(); await SystemApi.restart();
enqueueSnackbar(LL.APPLICATION_RESTARTING(), { variant: 'info' }); enqueueSnackbar(LL.APPLICATION_RESTARTING(), { variant: 'info' });
} catch (error: unknown) { } catch (error) {
enqueueSnackbar(extractErrorMessage(error, LL.PROBLEM_LOADING()), { variant: 'error' }); enqueueSnackbar(extractErrorMessage(error, LL.PROBLEM_LOADING()), { variant: 'error' });
} finally { } finally {
setConfirmRestart(false); setConfirmRestart(false);
@@ -180,7 +180,7 @@ const SystemStatusForm: FC = () => {
try { try {
await SystemApi.factoryReset(); await SystemApi.factoryReset();
enqueueSnackbar(LL.SYSTEM_FACTORY_TEXT(), { variant: 'info' }); enqueueSnackbar(LL.SYSTEM_FACTORY_TEXT(), { variant: 'info' });
} catch (error: unknown) { } catch (error) {
enqueueSnackbar(extractErrorMessage(error, LL.PROBLEM_UPDATING()), { variant: 'error' }); enqueueSnackbar(extractErrorMessage(error, LL.PROBLEM_UPDATING()), { variant: 'error' });
} finally { } finally {
setConfirmFactoryReset(false); setConfirmFactoryReset(false);

View File

@@ -364,7 +364,7 @@ const DashboardData: FC = () => {
const fetchCoreData = useCallback(async () => { const fetchCoreData = useCallback(async () => {
try { try {
setCoreData((await EMSESP.readCoreData()).data); setCoreData((await EMSESP.readCoreData()).data);
} catch (error: unknown) { } catch (error) {
enqueueSnackbar(extractErrorMessage(error, LL.PROBLEM_LOADING()), { variant: 'error' }); enqueueSnackbar(extractErrorMessage(error, LL.PROBLEM_LOADING()), { variant: 'error' });
} }
}, [enqueueSnackbar, LL]); }, [enqueueSnackbar, LL]);
@@ -385,7 +385,7 @@ const DashboardData: FC = () => {
const unique_id = parseInt(id); const unique_id = parseInt(id);
try { try {
setDeviceData((await EMSESP.readDeviceData({ id: unique_id })).data); setDeviceData((await EMSESP.readDeviceData({ id: unique_id })).data);
} catch (error: unknown) { } catch (error) {
enqueueSnackbar(extractErrorMessage(error, LL.PROBLEM_LOADING()), { variant: 'error' }); enqueueSnackbar(extractErrorMessage(error, LL.PROBLEM_LOADING()), { variant: 'error' });
} }
}; };
@@ -393,7 +393,7 @@ const DashboardData: FC = () => {
const fetchSensorData = async () => { const fetchSensorData = async () => {
try { try {
setSensorData((await EMSESP.readSensorData()).data); setSensorData((await EMSESP.readSensorData()).data);
} catch (error: unknown) { } catch (error) {
enqueueSnackbar(extractErrorMessage(error, LL.PROBLEM_LOADING()), { variant: 'error' }); enqueueSnackbar(extractErrorMessage(error, LL.PROBLEM_LOADING()), { variant: 'error' });
} }
}; };
@@ -474,7 +474,7 @@ const DashboardData: FC = () => {
enqueueSnackbar(LL.WRITE_COMMAND({ cmd: 'send' }), { variant: 'success' }); enqueueSnackbar(LL.WRITE_COMMAND({ cmd: 'send' }), { variant: 'success' });
} }
setDeviceValue(undefined); setDeviceValue(undefined);
} catch (error: unknown) { } catch (error) {
enqueueSnackbar(extractErrorMessage(error, LL.PROBLEM_UPDATING()), { variant: 'error' }); enqueueSnackbar(extractErrorMessage(error, LL.PROBLEM_UPDATING()), { variant: 'error' });
} finally { } finally {
refreshData(); refreshData();
@@ -566,7 +566,7 @@ const DashboardData: FC = () => {
enqueueSnackbar(LL.TEMP_SENSOR() + ' ' + LL.UPDATED(), { variant: 'success' }); enqueueSnackbar(LL.TEMP_SENSOR() + ' ' + LL.UPDATED(), { variant: 'success' });
} }
setSensor(undefined); setSensor(undefined);
} catch (error: unknown) { } catch (error) {
enqueueSnackbar(extractErrorMessage(error, LL.PROBLEM_UPDATING()), { variant: 'error' }); enqueueSnackbar(extractErrorMessage(error, LL.PROBLEM_UPDATING()), { variant: 'error' });
} finally { } finally {
setSensor(undefined); setSensor(undefined);
@@ -992,7 +992,7 @@ const DashboardData: FC = () => {
} else { } else {
enqueueSnackbar(LL.ANALOG_SENSOR() + ' ' + LL.REMOVED(), { variant: 'success' }); enqueueSnackbar(LL.ANALOG_SENSOR() + ' ' + LL.REMOVED(), { variant: 'success' });
} }
} catch (error: unknown) { } catch (error) {
enqueueSnackbar(extractErrorMessage(error, LL.PROBLEM_UPDATING()), { variant: 'error' }); enqueueSnackbar(extractErrorMessage(error, LL.PROBLEM_UPDATING()), { variant: 'error' });
} finally { } finally {
setAnalog(undefined); setAnalog(undefined);
@@ -1020,7 +1020,7 @@ const DashboardData: FC = () => {
} else { } else {
enqueueSnackbar(LL.ANALOG_SENSOR() + ' ' + LL.UPDATED(), { variant: 'success' }); enqueueSnackbar(LL.ANALOG_SENSOR() + ' ' + LL.UPDATED(), { variant: 'success' });
} }
} catch (error: unknown) { } catch (error) {
enqueueSnackbar(extractErrorMessage(error, LL.PROBLEM_UPDATING()), { variant: 'error' }); enqueueSnackbar(extractErrorMessage(error, LL.PROBLEM_UPDATING()), { variant: 'error' });
} finally { } finally {
setAnalog(undefined); setAnalog(undefined);

View File

@@ -149,7 +149,7 @@ const DashboardStatus: FC = () => {
try { try {
await EMSESP.scanDevices(); await EMSESP.scanDevices();
enqueueSnackbar(LL.SCANNING() + '...', { variant: 'info' }); enqueueSnackbar(LL.SCANNING() + '...', { variant: 'info' });
} catch (error: unknown) { } catch (error) {
enqueueSnackbar(extractErrorMessage(error, LL.PROBLEM_UPDATING()), { variant: 'error' }); enqueueSnackbar(extractErrorMessage(error, LL.PROBLEM_UPDATING()), { variant: 'error' });
} finally { } finally {
setConfirmScan(false); setConfirmScan(false);

View File

@@ -50,7 +50,7 @@ const HelpInformation: FC = () => {
} else { } else {
saveFile(response.data, endpoint); saveFile(response.data, endpoint);
} }
} catch (error: unknown) { } catch (error) {
enqueueSnackbar(extractErrorMessage(error, LL.PROBLEM_LOADING()), { variant: 'error' }); enqueueSnackbar(extractErrorMessage(error, LL.PROBLEM_LOADING()), { variant: 'error' });
} }
}; };

View File

@@ -68,7 +68,7 @@ const SettingsApplication: FC = () => {
eth_clock_mode: response.data.eth_clock_mode eth_clock_mode: response.data.eth_clock_mode
}); });
} }
} catch (error: unknown) { } catch (error) {
enqueueSnackbar(extractErrorMessage(error, LL.PROBLEM_UPDATING()), { variant: 'error' }); enqueueSnackbar(extractErrorMessage(error, LL.PROBLEM_UPDATING()), { variant: 'error' });
} finally { } finally {
setProcessingBoard(false); setProcessingBoard(false);
@@ -107,7 +107,7 @@ const SettingsApplication: FC = () => {
try { try {
await EMSESP.restart(); await EMSESP.restart();
enqueueSnackbar(LL.APPLICATION_RESTARTING(), { variant: 'info' }); enqueueSnackbar(LL.APPLICATION_RESTARTING(), { variant: 'info' });
} catch (error: unknown) { } catch (error) {
enqueueSnackbar(extractErrorMessage(error, LL.PROBLEM_UPDATING()), { variant: 'error' }); enqueueSnackbar(extractErrorMessage(error, LL.PROBLEM_UPDATING()), { variant: 'error' });
} }
}; };

View File

@@ -131,7 +131,7 @@ const SettingsCustomization: FC = () => {
const fetchDevices = useCallback(async () => { const fetchDevices = useCallback(async () => {
try { try {
setDevices((await EMSESP.readDevices()).data); setDevices((await EMSESP.readDevices()).data);
} catch (error: unknown) { } catch (error) {
setErrorMessage(extractErrorMessage(error, LL.PROBLEM_LOADING())); setErrorMessage(extractErrorMessage(error, LL.PROBLEM_LOADING()));
} }
}, [LL]); }, [LL]);
@@ -144,7 +144,7 @@ const SettingsCustomization: FC = () => {
try { try {
const new_deviceEntities = (await EMSESP.readDeviceEntities({ id: unique_id })).data; const new_deviceEntities = (await EMSESP.readDeviceEntities({ id: unique_id })).data;
setInitialMask(new_deviceEntities); setInitialMask(new_deviceEntities);
} catch (error: unknown) { } catch (error) {
setErrorMessage(extractErrorMessage(error, LL.PROBLEM_LOADING())); setErrorMessage(extractErrorMessage(error, LL.PROBLEM_LOADING()));
} }
}; };
@@ -243,7 +243,7 @@ const SettingsCustomization: FC = () => {
try { try {
await EMSESP.resetCustomizations(); await EMSESP.resetCustomizations();
enqueueSnackbar(LL.CUSTOMIZATIONS_RESTART(), { variant: 'info' }); enqueueSnackbar(LL.CUSTOMIZATIONS_RESTART(), { variant: 'info' });
} catch (error: unknown) { } catch (error) {
enqueueSnackbar(extractErrorMessage(error, LL.PROBLEM_UPDATING()), { variant: 'error' }); enqueueSnackbar(extractErrorMessage(error, LL.PROBLEM_UPDATING()), { variant: 'error' });
} finally { } finally {
setConfirmReset(false); setConfirmReset(false);
@@ -281,7 +281,7 @@ const SettingsCustomization: FC = () => {
} else { } else {
enqueueSnackbar(LL.PROBLEM_UPDATING(), { variant: 'error' }); enqueueSnackbar(LL.PROBLEM_UPDATING(), { variant: 'error' });
} }
} catch (error: unknown) { } catch (error) {
enqueueSnackbar(extractErrorMessage(error, LL.PROBLEM_UPDATING()), { variant: 'error' }); enqueueSnackbar(extractErrorMessage(error, LL.PROBLEM_UPDATING()), { variant: 'error' });
} }
setInitialMask(deviceEntities); setInitialMask(deviceEntities);

View File

@@ -1,7 +1,5 @@
import { AxiosError } from 'axios'; export const extractErrorMessage = (error: any, defaultMessage: string) => {
if (error.request) {
export const extractErrorMessage = (error: unknown, defaultMessage: string) => {
if (error instanceof AxiosError) {
return defaultMessage + ' (' + error.request.statusText + ')'; return defaultMessage + ' (' + error.request.statusText + ')';
} else if (error instanceof Error) { } else if (error instanceof Error) {
return defaultMessage + ' (' + error.message + ')'; return defaultMessage + ' (' + error.message + ')';

View File

@@ -26,7 +26,7 @@ export const useRest = <D>({ read, update }: RestRequestOptions<D>) => {
setErrorMessage(undefined); setErrorMessage(undefined);
try { try {
setData((await read()).data); setData((await read()).data);
} catch (error: unknown) { } catch (error) {
const message = extractErrorMessage(error, LL.PROBLEM_LOADING()); const message = extractErrorMessage(error, LL.PROBLEM_LOADING());
enqueueSnackbar(message, { variant: 'error' }); enqueueSnackbar(message, { variant: 'error' });
setErrorMessage(message); setErrorMessage(message);
@@ -49,7 +49,7 @@ export const useRest = <D>({ read, update }: RestRequestOptions<D>) => {
} else { } else {
enqueueSnackbar(LL.SETTINGS() + ' ' + LL.SAVED(), { variant: 'success' }); enqueueSnackbar(LL.SETTINGS() + ' ' + LL.SAVED(), { variant: 'success' });
} }
} catch (error: unknown) { } catch (error) {
const message = extractErrorMessage(error, LL.PROBLEM_UPDATING()); const message = extractErrorMessage(error, LL.PROBLEM_UPDATING());
enqueueSnackbar(message, { variant: 'error' }); enqueueSnackbar(message, { variant: 'error' });
setErrorMessage(message); setErrorMessage(message);

View File

@@ -14,6 +14,7 @@
"resolveJsonModule": true, "resolveJsonModule": true,
"isolatedModules": true, "isolatedModules": true,
"noEmit": true, "noEmit": true,
"useUnknownInCatchVariables": false,
"jsx": "react-jsx" "jsx": "react-jsx"
}, },
"include": ["src"] "include": ["src"]