| 12345678910111213141516171819202122232425262728293031323334353637383940 |
- import { WebAPICallResult } from '@slack/web-api';
- import { generateMarkdownSectionBlock } from './block-creater';
- import { generateWebClient } from './webclient-factory';
- export const postEphemeralErrors = async(
- rejectedResults: PromiseRejectedResult[],
- channelId: string,
- userId: string,
- botToken: string,
- ): Promise<WebAPICallResult|void> => {
- if (rejectedResults.length > 0) {
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- const client = generateWebClient(botToken);
- return client.chat.postEphemeral({
- text: 'Error occured.',
- channel: channelId,
- user: userId,
- blocks: [
- generateMarkdownSectionBlock('*Error occured:*'),
- ...rejectedResults.map((rejectedResult) => {
- const reason = rejectedResult.reason.toString();
- const resData = rejectedResult.reason.response?.data;
- const resDataMessage = resData?.message || resData?.toString();
- let errorMessage = reason;
- if (resDataMessage != null) {
- errorMessage += `\n Cause: ${resDataMessage}`;
- }
- return generateMarkdownSectionBlock(errorMessage);
- }),
- ],
- });
- }
- return;
- };
|