Improve webhook errror messages (#87044) (#87297)

* Initial work

* Fix variables to pull from

* Rename some variables

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Mike Côté 2021-01-05 10:23:03 -05:00 committed by GitHub
parent 965eb079d2
commit f5e6e4bc1b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -176,8 +176,14 @@ export async function executor(
const { error } = result;
if (error.response) {
const { status, statusText, headers: responseHeaders } = error.response;
const message = `[${status}] ${statusText}`;
const {
status,
statusText,
headers: responseHeaders,
data: { message: responseMessage },
} = error.response;
const responseMessageAsSuffix = responseMessage ? `: ${responseMessage}` : '';
const message = `[${status}] ${statusText}${responseMessageAsSuffix}`;
logger.error(`error on ${actionId} webhook event: ${message}`);
// The request was made and the server responded with a status code
// that falls out of the range of 2xx
@ -195,6 +201,10 @@ export async function executor(
);
}
return errorResultInvalid(actionId, message);
} else if (error.isAxiosError) {
const message = `[${error.code}] ${error.message}`;
logger.error(`error on ${actionId} webhook event: ${message}`);
return errorResultRequestFailed(actionId, message);
}
logger.error(`error on ${actionId} webhook action: unexpected error`);
@ -222,6 +232,21 @@ function errorResultInvalid(
};
}
function errorResultRequestFailed(
actionId: string,
serviceMessage: string
): ActionTypeExecutorResult<unknown> {
const errMessage = i18n.translate('xpack.actions.builtin.webhook.requestFailedErrorMessage', {
defaultMessage: 'error calling webhook, request failed',
});
return {
status: 'error',
message: errMessage,
actionId,
serviceMessage,
};
}
function errorResultUnexpectedError(actionId: string): ActionTypeExecutorResult<void> {
const errMessage = i18n.translate('xpack.actions.builtin.webhook.unreachableErrorMessage', {
defaultMessage: 'error calling webhook, unexpected error',