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 #189 from mgilangjanuar/staging
Browse files Browse the repository at this point in the history
hotfix: throw error details and update readme.md
  • Loading branch information
mgilangjanuar authored Jan 10, 2022
2 parents 71c6945 + b5ea171 commit 9cd56c5
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 21 deletions.
37 changes: 19 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,25 @@ This is the open source project of Google Drive/OneDrive/iCloud/Dropbox alternat

- Server variables

| env | required | description |
| ---------------------- | -------- | -------------------------------------- |
| RPS | no | Rate limit API per second, default: 20 |
| TG_API_ID | yes | Application ID from your Telegram App |
| TG_API_HASH | yes | Application hash from Telegram App |
| TG_BOT_TOKEN | yes | Telegram bot token |
| TG_BOT_OWNER_ID | yes | Chat ID for sending messages to you |
| DB_HOST | no | Database host URI, default: localhost |
| DB_NAME | yes | Database name |
| DB_PORT | no | Database port, default: 5432 |
| DB_USERNAME | yes | Database username |
| DB_PASSWORD | yes | Database password |
| GITHUB_TOKEN | yes | GitHub token for getting contributors |
| API_JWT_SECRET | yes | Random string for hashing auth token |
| FILES_JWT_SECRET | yes | Random string for encrypt public files |
| PAYPAL_CLIENT_ID | yes | Client ID for PayPal subscription |
| PAYPAL_CLIENT_SECRET | yes | Client secret for PayPal subscription |
| PAYPAL_PLAN_PREMIUM_ID | yes | Product ID for premium plan |
| env | required | description |
| ---------------------- | -------- | ------------------------------------------- |
| RPS | no | Rate limit API per second, default: 20 |
| TG_API_ID | yes | Application ID from your Telegram App |
| TG_API_HASH | yes | Application hash from Telegram App |
| TG_BOT_TOKEN | yes | Telegram bot token |
| TG_BOT_OWNER_ID | yes | Chat ID for sending messages to you |
| DB_HOST | no | Database host URI, default: localhost |
| DB_NAME | yes | Database name |
| DB_PORT | no | Database port, default: 5432 |
| DB_USERNAME | yes | Database username |
| DB_PASSWORD | yes | Database password |
| GITHUB_TOKEN | yes | GitHub token for getting contributors |
| API_JWT_SECRET | yes | Random string for hashing auth token |
| FILES_JWT_SECRET | yes | Random string for encrypt public files |
| PAYPAL_CLIENT_ID | yes | Client ID for PayPal subscription |
| PAYPAL_CLIENT_SECRET | yes | Client secret for PayPal subscription |
| PAYPAL_PLAN_PREMIUM_ID | yes | Product ID for premium plan |
| REDIS_URI | yes | Cache some responses from external services |

- Web variables

Expand Down
11 changes: 9 additions & 2 deletions server/src/api/base/Endpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,12 @@ export const Endpoint = {
}
console.error('RequestWrapper', error)
req.tg?.disconnect()
return next(error.code ? { status: error.code, body: { error: error.message, details: serializeError(error) } } : error)
const isValidCode = error.code && Number(error.code) > 99 && Number(error.code) < 599
return next(error.code ? {
status: isValidCode ? error.code : 500, body: {
error: error.message, details: serializeError(error)
}
} : error)
}
}
return await execute()
Expand Down Expand Up @@ -127,7 +132,9 @@ export const Endpoint = {
// process.exit(1)
// }
return next(error.code ? {
status: isValidCode ? error.code : 500, body: { error: error.message, ...isValidCode ? { details: serializeError(error) } : {} }
status: isValidCode ? error.code : 500, body: {
error: error.message, details: serializeError(error)
}
} : error)
}
}
Expand Down
3 changes: 2 additions & 1 deletion server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import morgan from 'morgan'
import path from 'path'
import { Pool } from 'pg'
import { RateLimiterPostgres } from 'rate-limiter-flexible'
import { serializeError } from 'serialize-error'
import * as Sentry from '@sentry/node'
import * as Tracing from '@sentry/tracing'
import { API } from './api'
Expand Down Expand Up @@ -126,7 +127,7 @@ app.use('/api', (req, res, next) => {
app.use(Sentry.Handlers.errorHandler())
app.use((err: { status?: number, body?: Record<string, any> }, _: Request, res: Response, __: NextFunction) => {
console.error(err)
return res.status(err.status || 500).send(err.body || { error: 'Something error' })
return res.status(err.status || 500).send(err.body || { error: 'Something error', details: serializeError(err) })
})

// serve web
Expand Down

0 comments on commit 9cd56c5

Please sign in to comment.