mirror of
https://fast.feibisi.com/https://github.com/parcelvoy/platform.git
synced 2025-08-28 11:46:02 +08:00
Adds better default error handling and docs (#621)
This commit is contained in:
parent
1527e01650
commit
2a780aab93
4 changed files with 51 additions and 13 deletions
|
@ -1,10 +1,12 @@
|
|||
import { DriverConfig } from '../config/env'
|
||||
import { logger } from '../config/logger'
|
||||
import Koa from 'koa'
|
||||
import BugSnagProvider, { BugSnagConfig } from './BugSnagProvider'
|
||||
import ErrorHandlerProvider, { ErrorHandlerProviderName } from './ErrorHandlerProvider'
|
||||
import SentryProvider, { SentryConfig } from './SentryProvider'
|
||||
import LoggerErrorProvider, { LoggerErrorConfig } from './LoggerProvider'
|
||||
|
||||
export type ErrorConfig = BugSnagConfig | SentryConfig
|
||||
export type ErrorConfig = BugSnagConfig | SentryConfig | LoggerErrorConfig
|
||||
|
||||
export interface ErrorHandlerTypeConfig extends DriverConfig {
|
||||
driver: ErrorHandlerProviderName
|
||||
|
@ -21,6 +23,8 @@ export default class ErrorHandler {
|
|||
this.provider = new BugSnagProvider(config)
|
||||
} else if (config?.driver === 'sentry') {
|
||||
this.provider = new SentryProvider(config)
|
||||
} else {
|
||||
this.provider = new LoggerErrorProvider()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -35,5 +39,6 @@ export default class ErrorHandler {
|
|||
? { ...context, ...error.context }
|
||||
: context,
|
||||
)
|
||||
if (!this.provider) logger.error(error)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import Koa from 'koa'
|
||||
|
||||
export type ErrorHandlerProviderName = 'bugsnag' | 'sentry'
|
||||
export type ErrorHandlerProviderName = 'bugsnag' | 'sentry' | 'logger'
|
||||
|
||||
export default interface ErrorHandlerProvider {
|
||||
attach(api: Koa): void
|
||||
|
|
19
apps/platform/src/error/LoggerProvider.ts
Normal file
19
apps/platform/src/error/LoggerProvider.ts
Normal file
|
@ -0,0 +1,19 @@
|
|||
import { ErrorHandlerTypeConfig } from './ErrorHandler'
|
||||
import ErrorHandlingProvider from './ErrorHandlerProvider'
|
||||
import { logger } from '../config/logger'
|
||||
|
||||
export interface LoggerErrorConfig extends ErrorHandlerTypeConfig {
|
||||
driver: 'logger'
|
||||
}
|
||||
|
||||
export default class LoggerErrorProvider implements ErrorHandlingProvider {
|
||||
|
||||
attach() { /** */ }
|
||||
|
||||
notify(error: Error, context?: Record<string, any>) {
|
||||
logger.error({
|
||||
error,
|
||||
context,
|
||||
}, error.message)
|
||||
}
|
||||
}
|
|
@ -3,14 +3,14 @@ Find below a list of all environment variables that can be set at launch to conf
|
|||
|
||||
|
||||
### General
|
||||
| key | type | required |
|
||||
| Key | Type | Required |
|
||||
|--|--|--|
|
||||
| BASE_URL | string | true |
|
||||
| PORT | number | true |
|
||||
| APP_SECRET | string | true |
|
||||
|
||||
### Database
|
||||
| key | type | required |
|
||||
| Key | Type | Required |
|
||||
|--|--|--|
|
||||
| DB_HOST | string | true |
|
||||
| DB_USERNAME | string | true |
|
||||
|
@ -18,9 +18,9 @@ Find below a list of all environment variables that can be set at launch to conf
|
|||
| DB_DATABASE | string | true |
|
||||
|
||||
### Queue
|
||||
| key | type | required | notes
|
||||
| Key | Type | Required | Notes
|
||||
|--|--|--|
|
||||
| QUEUE_DRIVER | 'sqs' or 'redis' or 'memory' | true |
|
||||
| QUEUE_DRIVER | `sqs` or `redis` or `memory` | true |
|
||||
| AWS_SQS_QUEUE_URL | string | If driver is SQS |
|
||||
| AWS_REGION | string | If driver is SQS |
|
||||
| AWS_ACCESS_KEY_ID | string | If driver is SQS |
|
||||
|
@ -32,7 +32,7 @@ Find below a list of all environment variables that can be set at launch to conf
|
|||
|
||||
|
||||
### Redis
|
||||
| key | type | required |
|
||||
| Key | Type | Required |
|
||||
|--|--|--|
|
||||
| REDIS_HOST | string | true |
|
||||
| REDIS_PORT | string | true |
|
||||
|
@ -41,10 +41,12 @@ Find below a list of all environment variables that can be set at launch to conf
|
|||
| REDIS_PASSWORD | string | false |
|
||||
|
||||
### Storage
|
||||
| key | type | required |
|
||||
See the [Storage](/advanced/storage) page for more details on how to use different storage options.
|
||||
|
||||
| Key | Type | Required |
|
||||
|--|--|--|
|
||||
| STORAGE_BASE_URL | string | true |
|
||||
| STORAGE_DRIVER | 's3' or 'local' | true |
|
||||
| STORAGE_DRIVER | `s3` or `local` | true |
|
||||
| STORAGE_S3_BUCKET | string | If driver is S3 |
|
||||
| STORAGE_S3_ENDPOINT | string | false |
|
||||
| STORAGE_S3_FORCE_PATH_STYLE | boolean | false |
|
||||
|
@ -53,9 +55,9 @@ Find below a list of all environment variables that can be set at launch to conf
|
|||
| AWS_SECRET_ACCESS_KEY | string | If driver is S3 |
|
||||
|
||||
### Auth
|
||||
| key | type | required | notes
|
||||
| Key | Type | Required | Notes
|
||||
|--|--|--|
|
||||
| AUTH_DRIVER | 'basic', 'google', 'openid', 'saml' | true | Can be multiple
|
||||
| AUTH_DRIVER | `basic`, `google`, `openid`, `saml` | true | Can be multiple
|
||||
| AUTH_BASIC_EMAIL | string | If driver is Basic |
|
||||
| AUTH_BASIC_PASSWORD | string | If driver is Basic |
|
||||
| AUTH_BASIC_NAME | string | false |
|
||||
|
@ -77,7 +79,19 @@ Find below a list of all environment variables that can be set at launch to conf
|
|||
| AUTH_GOOGLE_NAME | string | false |
|
||||
|
||||
### Tracking
|
||||
| key | type | required |
|
||||
| Key | Type | Required |
|
||||
|--|--|--|
|
||||
| TRACKING_LINK_WRAP | boolean | false
|
||||
| TRACKING_DEEPLINK_MIRROR_URL | string | false
|
||||
| TRACKING_DEEPLINK_MIRROR_URL | string | false
|
||||
|
||||
### Error Handling
|
||||
Parcelvoy supports both logging information about the system to the terminal as well as logging errors to either Bugsnag or Sentry.
|
||||
|
||||
| Key | Type | Required | Description
|
||||
|--|--|--|--|
|
||||
| LOG_LEVEL | `info`, `trace`, `warn`, `error` | false | What segment of logs to output |
|
||||
| LOG_COMPILED_MESSAGE | boolean | false | Should the entire message from a send be stored in the event table |
|
||||
| LOG_PRETTY_PRINT | boolean | false | Should logs pretty print to terminal |
|
||||
| ERROR_DRIVER | `sentry`, `bugsnag` or `logger` | false | What error handling client to use |
|
||||
| ERROR_BUGSNAG_API_KEY | string | If driver is Bugsnag | The API key to the Node.js Bugsnag project |
|
||||
| ERROR_SENTRY_DSN | string | If driver is Sentry | The DNS for the Sentry Node.js project |
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue