Skip to content

Commit 1767037

Browse files
authored
Improve slack alert error logs (#6716)
1 parent 92898ce commit 1767037

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

.changeset/brave-snails-design.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'hive': patch
3+
---
4+
5+
Improve slack alert error logs

packages/services/api/src/modules/alerts/providers/adapters/slack.ts

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Inject, Injectable } from 'graphql-modules';
22
import { CriticalityLevel } from '@graphql-inspector/core';
33
import { SchemaChangeType } from '@hive/storage';
4-
import { MessageAttachment, WebClient } from '@slack/web-api';
4+
import { ErrorCode, MessageAttachment, WebAPICallError, WebClient } from '@slack/web-api';
55
import { Logger } from '../../../shared/providers/logger';
66
import { WEB_APP_URL } from '../../../shared/providers/tokens';
77
import {
@@ -77,8 +77,8 @@ export class SlackCommunicationAdapter implements CommunicationAdapter {
7777
unfurl_media: false,
7878
});
7979
}
80-
} catch (error) {
81-
this.logger.error(`Failed to send Slack notification`, error);
80+
} catch (error: any) {
81+
this.handleSlackClientError(error);
8282
}
8383
}
8484

@@ -120,13 +120,35 @@ export class SlackCommunicationAdapter implements CommunicationAdapter {
120120
].join('\n'),
121121
});
122122
} catch (error) {
123-
this.logger.error(`Failed to send Slack notification`, error);
123+
this.handleSlackClientError(error);
124124
}
125125
}
126126

127127
private pluralize(word: string, num: number): string {
128128
return word + (num > 1 ? 's' : '');
129129
}
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+
}
130152
}
131153

132154
function createAttachments(changes: readonly SchemaChangeType[], messages: readonly string[]) {

packages/services/api/src/modules/schema/providers/registry-checks.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,6 @@ export class RegistryChecks {
287287
} satisfies CheckResult;
288288
}
289289

290-
this.logger.debug('No validation errors');
291-
292290
if (!result.sdl) {
293291
throw new Error('No SDL, but no errors either');
294292
}

0 commit comments

Comments
 (0)