diff --git a/README.md b/README.md index 16db1f185..d9bb6d8c3 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/server/src/api/base/Endpoint.ts b/server/src/api/base/Endpoint.ts index 82c3e7e5f..1a994a628 100644 --- a/server/src/api/base/Endpoint.ts +++ b/server/src/api/base/Endpoint.ts @@ -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() @@ -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) } } diff --git a/server/src/index.ts b/server/src/index.ts index 911c9efa4..d9a01e2e8 100644 --- a/server/src/index.ts +++ b/server/src/index.ts @@ -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' @@ -126,7 +127,7 @@ app.use('/api', (req, res, next) => { app.use(Sentry.Handlers.errorHandler()) app.use((err: { status?: number, body?: Record }, _: 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