Skip to content

Commit

Permalink
Adds better default error handling and docs (#621)
Browse files Browse the repository at this point in the history
  • Loading branch information
pushchris authored Jan 26, 2025
1 parent 1527e01 commit 2a780aa
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 13 deletions.
7 changes: 6 additions & 1 deletion apps/platform/src/error/ErrorHandler.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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()
}
}

Expand All @@ -35,5 +39,6 @@ export default class ErrorHandler {
? { ...context, ...error.context }
: context,
)
if (!this.provider) logger.error(error)
}
}
2 changes: 1 addition & 1 deletion apps/platform/src/error/ErrorHandlerProvider.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down
19 changes: 19 additions & 0 deletions apps/platform/src/error/LoggerProvider.ts
Original file line number Diff line number Diff line change
@@ -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)
}
}
36 changes: 25 additions & 11 deletions docs/docs/advanced/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@ 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 |
| DB_PORT | number | true |
| 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 |
Expand All @@ -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 |
Expand All @@ -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 |
Expand All @@ -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 |
Expand All @@ -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 |

0 comments on commit 2a780aa

Please sign in to comment.