FlourishHealth / ferns-api

Apache License 2.0
1 stars 3 forks source link

Allow setting Sentry options in expressServer #429

Closed joshgachnang closed 1 month ago

joshgachnang commented 1 month ago

We'll use this to e.g. add more ignoreErrors options.

codiumai-pr-agent-pro[bot] commented 1 month ago

PR Reviewer Guide 🔍

⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ Key issues to review

Error Handling
The new `sentryOptions` parameter is not type-checked, which could lead to runtime errors if invalid options are provided. Code Duplication
The default Sentry options are defined within the function, which could lead to duplication if used elsewhere. Consider moving these to a separate configuration file.
codiumai-pr-agent-pro[bot] commented 1 month ago

PR Code Suggestions ✨

CategorySuggestion                                                                                                                                    Score
Best practice
Add a more specific type annotation for function parameters to improve type safety ___ **Consider adding a type annotation for the options parameter in the initializeRoutes
function to improve type safety and code readability.** [src/expressServer.ts [204-208]](https://github.com/FlourishHealth/ferns-api/pull/429/files#diff-d8c51792951866599be44999fb26695bc96b6b7435d64cab68e024b90efdeb1cR204-R208) ```diff function initializeRoutes( UserModel: UserMongooseModel, addRoutes: AddRoutes, - options: InitializeRoutesOptions = {} + options: Partial = {} ) { ``` - [ ] **Apply this suggestion**
Suggestion importance[1-10]: 9 Why: Adding a `Partial` type annotation for the `options` parameter enhances type safety by explicitly allowing partial objects, which is a best practice for handling optional configuration objects.
9
Enhancement
Simplify object merging using the spread operator instead of lodash merge ___ **Consider using the ??= nullish coalescing assignment operator to simplify the
merging of default options with provided options.** [src/expressServer.ts [57]](https://github.com/FlourishHealth/ferns-api/pull/429/files#diff-d8c51792951866599be44999fb26695bc96b6b7435d64cab68e024b90efdeb1cR57-R57) ```diff -Sentry.init(merge({}, defaultSentryOptions, sentryOptions)); +Sentry.init({ ...defaultSentryOptions, ...sentryOptions }); ``` - [ ] **Apply this suggestion**
Suggestion importance[1-10]: 8 Why: Using the spread operator for merging objects is a simpler and more modern approach compared to lodash's `merge`, which can improve code readability and performance in this context.
8
Use object destructuring for function parameters to provide default values and improve readability ___ **Consider using object destructuring for the sentryOptions parameter in the
setupErrorLogging function to provide default values and improve readability.** [src/expressServer.ts [22-26]](https://github.com/FlourishHealth/ferns-api/pull/429/files#diff-d8c51792951866599be44999fb26695bc96b6b7435d64cab68e024b90efdeb1cR22-R26) ```diff export function setupErrorLogging( app: express.Application, ignoreTraces: string[] = [], - sentryOptions?: Sentry.NodeOptions + { dsn, environment, ...otherOptions }: Sentry.NodeOptions = {} ) { ``` - [ ] **Apply this suggestion**
Suggestion importance[1-10]: 7 Why: The suggestion to use object destructuring for the `sentryOptions` parameter can improve code readability and provide a clear way to set default values, which is beneficial for maintainability.
7