diff --git a/package.json b/package.json index ee00c67e0..f104a72a4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "teledrive", - "version": "1.6.1", + "version": "1.6.2", "repository": "git@github.com:mgilangjanuar/teledrive.git", "author": "M Gilang Januar ", "license": "MIT", diff --git a/server/package.json b/server/package.json index 8d7ec9926..7391bd376 100644 --- a/server/package.json +++ b/server/package.json @@ -1,6 +1,6 @@ { "name": "server", - "version": "1.6.1", + "version": "1.6.2", "main": "dist/index.js", "license": "MIT", "private": true, diff --git a/server/src/api/base/Endpoint.ts b/server/src/api/base/Endpoint.ts index be487f684..82c3e7e5f 100644 --- a/server/src/api/base/Endpoint.ts +++ b/server/src/api/base/Endpoint.ts @@ -121,9 +121,11 @@ export const Endpoint = { return await execute() } console.error('handler', error.message) - // process.exit(1) req.tg?.disconnect() const isValidCode = error.code && Number(error.code) > 99 && Number(error.code) < 599 + // if (!isValidCode) { + // process.exit(1) + // } return next(error.code ? { status: isValidCode ? error.code : 500, body: { error: error.message, ...isValidCode ? { details: serializeError(error) } : {} } } : error) diff --git a/server/src/index.ts b/server/src/index.ts index 823a255a1..911c9efa4 100644 --- a/server/src/index.ts +++ b/server/src/index.ts @@ -116,7 +116,7 @@ app.get('/security.txt', (_, res) => { app.use('/api', (req, res, next) => { rateLimiter.consume(req.headers['cf-connecting-ip'] as string || req.ip).then(() => next()).catch(error => { if (error.msBeforeNext) { - return res.status(429).setHeader('retry-after', error.msBeforeNext).send({ error: 'Too many requests' }) + return res.status(429).setHeader('retry-after', error.msBeforeNext).send({ error: 'Too many requests', retryAfter: error.msBeforeNext }) } throw error }) diff --git a/web/package.json b/web/package.json index 74f6d65c6..ed67a71d7 100644 --- a/web/package.json +++ b/web/package.json @@ -1,6 +1,6 @@ { "name": "web", - "version": "1.6.1", + "version": "1.6.2", "private": true, "dependencies": { "@craco/craco": "^6.3.0", diff --git a/web/src/pages/dashboard/components/Upload.tsx b/web/src/pages/dashboard/components/Upload.tsx index d2c74bf9a..66bd52294 100644 --- a/web/src/pages/dashboard/components/Upload.tsx +++ b/web/src/pages/dashboard/components/Upload.tsx @@ -102,6 +102,7 @@ const Upload: React.FC = ({ dataFileList: [fileList, setFileList], parent if (!deleted) { window.onbeforeunload = undefined as any notification.success({ + key: 'fileUploaded', message: 'Success', description: `File ${file.name} uploaded successfully` }) @@ -111,6 +112,7 @@ const Upload: React.FC = ({ dataFileList: [fileList, setFileList], parent console.error(error) notification.close(`upload-${file.uid}`) notification.error({ + key: 'fileUploadError', message: error?.response?.status || 'Something error', ...error?.response?.data ? { description: error.response.data.error } : {} }) diff --git a/web/src/utils/Fetcher.ts b/web/src/utils/Fetcher.ts index 69a210918..3660b19f4 100644 --- a/web/src/utils/Fetcher.ts +++ b/web/src/utils/Fetcher.ts @@ -7,6 +7,18 @@ export const req = axios.create({ withCredentials: true }) +req.interceptors.response.use(response => response, async error => { + const { config, response: { status, data } } = error + if (status === 401) { + await req.post('/auth/refreshToken') + return await req(config) + } else if (status === 429) { + await new Promise(res => setTimeout(res, data.retryAfter || 1000)) + return await req(config) + } + throw error +}) + export const fetcher = async (url: string, authorization?: string): Promise => { const fetch = async () => { const { data } = await req.get(url, { @@ -14,25 +26,26 @@ export const fetcher = async (url: string, authorization?: string): Promise withCredentials: true }) return data } + return await fetch() - const execute = async () => { - try { - return await fetch() - } catch ({ response }) { - if ((response as any)?.status === 401) { - try { - await req.post('/auth/refreshToken') - return await fetch() - } catch (error) { - throw response - } - } else if ((response as any)?.status === 429) { - await new Promise(res => setTimeout(res, (response as any).headers?.['retry-after'] || 1000)) - // return await fetch() - return await execute() - } - throw response - } - } - return await execute() + // const execute = async () => { + // try { + // return await fetch() + // } catch ({ response }) { + // if ((response as any)?.status === 401) { + // try { + // await req.post('/auth/refreshToken') + // return await fetch() + // } catch (error) { + // throw response + // } + // } else if ((response as any)?.status === 429) { + // await new Promise(res => setTimeout(res, (response as any).headers?.['retry-after'] || 1000)) + // // return await fetch() + // return await execute() + // } + // throw response + // } + // } + // return await execute() } \ No newline at end of file