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 webhook errror messages to be more specific #87044

Merged
merged 5 commits into from
Jan 5, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions x-pack/plugins/actions/server/builtin_action_types/webhook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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`);
Expand Down Expand Up @@ -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',
Expand Down