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

Fix common router request handler issue #32275

Merged
merged 3 commits into from
Mar 6, 2019

Conversation

jen-huang
Copy link
Contributor

Change requestHandler wrapper to await the real handler before returning it. Without this change, any errors coming back from ES results in a 500 status and code never reaches the error handling in the catch block.

@jen-huang jen-huang added v8.0.0 Team:Kibana Management Dev Tools, Index Management, Upgrade Assistant, ILM, Ingest Node Pipelines, and more v7.2.0 labels Mar 1, 2019
@elasticmachine
Copy link
Contributor

Pinging @elastic/es-ui

} catch (err) {
if (isEsError(err)) {
throw wrapEsError(err);
return wrapEsError(err);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

usage of throw wasn't an issue, but I changed it to return since that is more commonly used to return errors in x-pack server code

Copy link
Contributor

Choose a reason for hiding this comment

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

@jen-huang Just seeing this. Have you tested this? It seems that by not throwing we would never be able to catch an error...

export const callWithRequestFactory = (server, request) => {
return (...args) => {
return callWithRequest(server)(request, ...args);
const callWithRequest = server => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this also wasn't necessarily an issue, but since this is now common code shared by multiple plugins, it should be a true factory

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Copy link
Contributor

@bmcconaghy bmcconaghy left a comment

Choose a reason for hiding this comment

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

code LGTM

Copy link
Contributor

@cjcenizal cjcenizal left a comment

Choose a reason for hiding this comment

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

Tested locally, code LGTM! Had one suggestion for simplifying the code.

const cluster = server.plugins.elasticsearch.getCluster('data');
return cluster.callWithRequest;
};
return once(callWithRequest)(server)(request, ...args);
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm sure we've had discussion about this before and I just missed it, but what's the benefit of using once here? If it's not needed, then this code could be simplified a bit. I tested this locally and it seemed OK:

export const callWithRequestFactory = (server, request) => {
  const { callWithRequest } = server.plugins.elasticsearch.getCluster('data');
  return (...args) => {
    return callWithRequest(request, ...args);
  };
};

Copy link
Contributor Author

Choose a reason for hiding this comment

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

once was used in the original code to safeguard against multiple factory calls. now that the factory code for call with request and license checker is shared, you're right that it is no longer needed. I pushed an update to remove once from both factories

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@jen-huang jen-huang merged commit 6f4fedc into elastic:master Mar 6, 2019
@jen-huang jen-huang deleted the fix/shared-router branch March 6, 2019 22:52
jen-huang added a commit to jen-huang/kibana that referenced this pull request Mar 6, 2019
* Add `await` to common router request handler

* Remove once() from common license checker and call with request factories
jen-huang added a commit that referenced this pull request Mar 6, 2019
* Add `await` to common router request handler

* Remove once() from common license checker and call with request factories
PhilippBaranovskiy pushed a commit to PhilippBaranovskiy/kibana that referenced this pull request Mar 7, 2019
* Add `await` to common router request handler

* Remove once() from common license checker and call with request factories
@cjcenizal cjcenizal added the non-issue Indicates to automation that a pull request should not appear in the release notes label May 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
non-issue Indicates to automation that a pull request should not appear in the release notes Team:Kibana Management Dev Tools, Index Management, Upgrade Assistant, ILM, Ingest Node Pipelines, and more v7.2.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants