|
1 | 1 | import { Inject, Injectable } from 'graphql-modules';
|
2 | 2 | import { CriticalityLevel } from '@graphql-inspector/core';
|
3 | 3 | import { SchemaChangeType } from '@hive/storage';
|
4 |
| -import { MessageAttachment, WebClient } from '@slack/web-api'; |
| 4 | +import { ErrorCode, MessageAttachment, WebAPICallError, WebClient } from '@slack/web-api'; |
5 | 5 | import { Logger } from '../../../shared/providers/logger';
|
6 | 6 | import { WEB_APP_URL } from '../../../shared/providers/tokens';
|
7 | 7 | import {
|
@@ -77,8 +77,8 @@ export class SlackCommunicationAdapter implements CommunicationAdapter {
|
77 | 77 | unfurl_media: false,
|
78 | 78 | });
|
79 | 79 | }
|
80 |
| - } catch (error) { |
81 |
| - this.logger.error(`Failed to send Slack notification`, error); |
| 80 | + } catch (error: any) { |
| 81 | + this.handleSlackClientError(error); |
82 | 82 | }
|
83 | 83 | }
|
84 | 84 |
|
@@ -120,13 +120,35 @@ export class SlackCommunicationAdapter implements CommunicationAdapter {
|
120 | 120 | ].join('\n'),
|
121 | 121 | });
|
122 | 122 | } catch (error) {
|
123 |
| - this.logger.error(`Failed to send Slack notification`, error); |
| 123 | + this.handleSlackClientError(error); |
124 | 124 | }
|
125 | 125 | }
|
126 | 126 |
|
127 | 127 | private pluralize(word: string, num: number): string {
|
128 | 128 | return word + (num > 1 ? 's' : '');
|
129 | 129 | }
|
| 130 | + |
| 131 | + private handleSlackClientError(error: any): void { |
| 132 | + // Failed to send Slack notification |
| 133 | + const err = error as WebAPICallError; |
| 134 | + if (err.code === ErrorCode.PlatformError) { |
| 135 | + // This is most likely due to channel_not_found but could also be authorization logic. Any platform error |
| 136 | + // is going to be an error in the input or creds. |
| 137 | + this.logger.warn( |
| 138 | + `Failed to send Slack notification due to a PlatformError (message=%s, error=%s)`, |
| 139 | + err.message, |
| 140 | + err.data.error, |
| 141 | + ); |
| 142 | + } else if (err.code === ErrorCode.HTTPError) { |
| 143 | + this.logger.error( |
| 144 | + `Failed to send Slack notification due to a HTTPError (message=%s, statusCode=%i)`, |
| 145 | + err.message, |
| 146 | + err.statusCode, |
| 147 | + ); |
| 148 | + } else { |
| 149 | + this.logger.error(`Failed to send Slack notification (message=%s)`, err.message); |
| 150 | + } |
| 151 | + } |
130 | 152 | }
|
131 | 153 |
|
132 | 154 | function createAttachments(changes: readonly SchemaChangeType[], messages: readonly string[]) {
|
|
0 commit comments