Skip to content

Commit

Permalink
Handle Unhandled events with global errors (#1488)
Browse files Browse the repository at this point in the history
* Handle Unhandled events with global errors

* rush change

* fix integration test

* fix event store reduce super kind

* Update pnpm-lock.yaml after merge

---------

Co-authored-by: Castro, Mario <[email protected]>
  • Loading branch information
gonzalojaubert and Castro, Mario authored Jul 31, 2024
1 parent 9199bbb commit c474f64
Show file tree
Hide file tree
Showing 11 changed files with 240 additions and 114 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@boostercloud/framework-core",
"comment": "Handle non-found events with global error handler",
"type": "minor"
}
],
"packageName": "@boostercloud/framework-core"
}
119 changes: 61 additions & 58 deletions common/config/rush/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 11 additions & 4 deletions packages/framework-core/src/booster-global-error-dispatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
ProjectionGlobalError,
SnapshotPersistHandlerGlobalError,
QueryHandlerGlobalError,
EventGlobalError,
} from '@boostercloud/framework-types'
import { getLogger } from '@boostercloud/framework-common-helpers'

Expand Down Expand Up @@ -48,14 +49,14 @@ export class BoosterGlobalErrorDispatcher {
case SnapshotPersistHandlerGlobalError:
newError = await this.handleSnapshotPersistError(error)
break
case EventGlobalError:
newError = await this.handleEventError(error)
break
}

newError = await this.handleGenericError(newError)
} catch (e) {
logger.error(
`Unhandled error inside the global error handler. When handling error ${error.originalError}, another error occurred`,
e
)
logger.error(`Unhandled error inside the global error handler. When handling error ${error.originalError}`, e)
return e
}
if (newError) return newError
Expand Down Expand Up @@ -112,6 +113,12 @@ export class BoosterGlobalErrorDispatcher {
return this.errorHandler.onSnapshotPersistError(currentError.originalError, currentError.snapshot)
}

private async handleEventError(error: GlobalErrorContainer): Promise<Error | undefined> {
if (!this.errorHandler || !this.errorHandler.onEventError) throw error.originalError
const currentError = error as EventGlobalError
return await this.errorHandler.onEventError(currentError.originalError, currentError.eventEnvelope)
}

private async handleGenericError(error: Error | undefined): Promise<Error | undefined> {
if (!error) return undefined
if (!this.errorHandler || !this.errorHandler.onError) throw error
Expand Down
Loading

0 comments on commit c474f64

Please sign in to comment.