Skip to content
This repository has been archived by the owner on Apr 23, 2024. It is now read-only.

Commit

Permalink
Merge pull request #188 from mgilangjanuar/staging
Browse files Browse the repository at this point in the history
Release v1.6.2
  • Loading branch information
mgilangjanuar authored Jan 10, 2022
2 parents 345c933 + 9693db1 commit 71c6945
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 25 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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 <mgilangjanuar@gmail.com>",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "server",
"version": "1.6.1",
"version": "1.6.2",
"main": "dist/index.js",
"license": "MIT",
"private": true,
Expand Down
4 changes: 3 additions & 1 deletion server/src/api/base/Endpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
Expand Down
2 changes: 1 addition & 1 deletion web/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "web",
"version": "1.6.1",
"version": "1.6.2",
"private": true,
"dependencies": {
"@craco/craco": "^6.3.0",
Expand Down
2 changes: 2 additions & 0 deletions web/src/pages/dashboard/components/Upload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ const Upload: React.FC<Props> = ({ dataFileList: [fileList, setFileList], parent
if (!deleted) {
window.onbeforeunload = undefined as any
notification.success({
key: 'fileUploaded',
message: 'Success',
description: `File ${file.name} uploaded successfully`
})
Expand All @@ -111,6 +112,7 @@ const Upload: React.FC<Props> = ({ 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 } : {}
})
Expand Down
53 changes: 33 additions & 20 deletions web/src/utils/Fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,45 @@ 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<any> => {
const fetch = async () => {
const { data } = await req.get(url, {
...authorization ? { headers: { authorization: `Bearer ${authorization}` } } : {},
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()
}

0 comments on commit 71c6945

Please sign in to comment.