Skip to content

Commit

Permalink
Improve webhook errror messages (#87044) (#87299)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
mikecote and kibanamachine authored Jan 5, 2021
1 parent 0af1d4b commit 6dfce9f
Showing 1 changed file with 27 additions and 2 deletions.
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

0 comments on commit 6dfce9f

Please sign in to comment.