Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Streams] Centralize error handling #207858

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

dgieselaar
Copy link
Member

Centralizes the error handling by:

  • creating a base StatusError exception that reports a status code
  • having all known errors extend from StatusError and setting a default status code for that error
  • handling both ES response and status errors into a single place, converting them into Boom errors

@dgieselaar dgieselaar added release_note:skip Skip the PR/issue when compiling release notes v9.0.0 backport:version Backport to applied version labels v8.18.0 Feature:Streams This is the label for the Streams Project labels Jan 22, 2025
@dgieselaar dgieselaar self-assigned this Jan 22, 2025
@dgieselaar dgieselaar requested a review from a team as a code owner January 22, 2025 15:18
export const createServerRoute = createServerRouteFactory<StreamsRouteHandlerResources>();
const createPlainStreamsServerRoute = createServerRouteFactory<StreamsRouteHandlerResources>();

export const createServerRoute: CreateServerRouteFactory<
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not trying to make things more complicated, but this seems very useful in general - should we move this and StatusError into the helper package?

Not a blocker.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, would like to see more use cases (not sure about subclassing etc) but will share with the devex wg

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The SLO plugin did something like this a bit back, I guess we're still waiting for the third use case to generalize over.

Copy link
Member Author

@dgieselaar dgieselaar Jan 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I just had a look, the way it's implemented in the SLO plugin is that it loses all type fidelity

@@ -48,11 +47,6 @@ export const retryTransientEsErrors = async <T>(
await setTimeout(retryDelaySec * 1000);
return retryTransientEsErrors(esCall, { logger, attempt: retryCount });
}

if (e.meta?.body?.error?.type === 'security_exception') {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm just propagating the ES error here

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

✅ unchanged

cc @dgieselaar

Copy link
Contributor

@flash1293 flash1293 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks mostly good to me, not sure about one case of status-code <-> exception class mapping, but no second round of review necessary

constructor(error: errors.ResponseError) {
super(
error.body?.error?.reason ||
error.body?.error?.caused_by?.reason ||
error.message ||
'Unknown error'
'Unknown error',
400
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like this is not necessarily a 400, should we just forward what's coming from Elasticsearch here instead?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:version Backport to applied version labels Feature:Streams This is the label for the Streams Project release_note:skip Skip the PR/issue when compiling release notes v8.18.0 v9.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants