-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,13 +6,12 @@ | |
|
||
import { once } from 'lodash'; | ||
|
||
const callWithRequest = once(server => { | ||
const cluster = server.plugins.elasticsearch.getCluster('data'); | ||
return cluster.callWithRequest; | ||
}); | ||
|
||
export const callWithRequestFactory = (server, request) => { | ||
return (...args) => { | ||
return callWithRequest(server)(request, ...args); | ||
const callWithRequest = server => { | ||
const cluster = server.plugins.elasticsearch.getCluster('data'); | ||
return cluster.callWithRequest; | ||
}; | ||
return once(callWithRequest)(server)(request, ...args); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 export const callWithRequestFactory = (server, request) => {
const { callWithRequest } = server.plugins.elasticsearch.getCluster('data');
return (...args) => {
return callWithRequest(request, ...args);
};
}; There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
}; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,13 +16,13 @@ export const createRouter = (server, pluginId, apiBasePath = '') => { | |
const requestHandler = (handler) => async (request, h) => { | ||
const callWithRequest = callWithRequestFactory(server, request); | ||
try { | ||
return handler(request, callWithRequest, h); | ||
return await handler(request, callWithRequest, h); | ||
} catch (err) { | ||
if (isEsError(err)) { | ||
throw wrapEsError(err); | ||
return wrapEsError(err); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. usage of There was a problem hiding this comment. Choose a reason for hiding this commentThe 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... |
||
} | ||
|
||
throw wrapUnknownError(err); | ||
return wrapUnknownError(err); | ||
} | ||
}; | ||
|
||
|
There was a problem hiding this comment.
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