Skip to content

Commit

Permalink
create notifySlack functions
Browse files Browse the repository at this point in the history
  • Loading branch information
celineung authored and JeromeBu committed Jan 23, 2025
1 parent cf39f76 commit 586bf93
Show file tree
Hide file tree
Showing 17 changed files with 153 additions and 117 deletions.
4 changes: 4 additions & 0 deletions back/src/config/bootstrap/appConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ export class AppConfig {
return this.env.DISCORD_WEBHOOK_URL;
}

public get slackBotToken(): string | undefined {
return this.env.SLACK_BOT_TOKEN;
}

public get documentGateway() {
return this.#throwIfNotInArray({
authorizedValues: ["NONE", "S3"],
Expand Down
4 changes: 2 additions & 2 deletions back/src/config/helpers/handleHttpJsonResponseError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Request, Response } from "express";
import { HttpError, HttpErrorResponseBody } from "shared";
import { ZodError } from "zod";
import { LoggerParamsWithMessage, createLogger } from "../../utils/logger";
import { notifyObjectDiscord } from "../../utils/notifyDiscord";
import { notifyObjectToTeam } from "../../utils/notifyTeam";

const logger = createLogger(__filename);

Expand Down Expand Up @@ -105,5 +105,5 @@ const logErrorAndNotifyDiscord = (
};

logger.error(params);
notifyObjectDiscord(params);
notifyObjectToTeam(params);
};
4 changes: 2 additions & 2 deletions back/src/config/pg/kysely/kyselyUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
import { Pool, QueryResultRow } from "pg";
import { Falsy } from "ramda";
import { createLogger } from "../../../utils/logger";
import { notifyObjectDiscord } from "../../../utils/notifyDiscord";
import { notifyObjectToTeam } from "../../../utils/notifyTeam";
import { Database } from "./model/database";

export const jsonBuildObject = <O extends Record<string, Expression<unknown>>>(
Expand Down Expand Up @@ -63,7 +63,7 @@ export const makeKyselyDb = (pool: Pool, options?: KyselyOptions): KyselyDb => {
params: event.query.parameters,
},
};
notifyObjectDiscord(params);
notifyObjectToTeam(params);
logger.error(params);
} else if (event.queryDurationMillis > 1_000) {
logger.warn({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ import {
LoggerParamsWithMessage,
createLogger,
} from "../../../../utils/logger";
import {
notifyDiscord,
notifyObjectDiscord,
} from "../../../../utils/notifyDiscord";
import { notifyObjectToTeam, notifyTeam } from "../../../../utils/notifyTeam";
import { InMemoryCachingGateway } from "../../../core/caching-gateway/adapters/InMemoryCachingGateway";
import {
RetryStrategy,
Expand Down Expand Up @@ -175,7 +172,7 @@ export class HttpFranceTravailGateway implements FranceTravailGateway {
},
});

notifyDiscord(
notifyTeam(
`HttpFranceTravailGateway notAxiosError ${
ftConvention.originalId
}: ${JSON.stringify(error)}`,
Expand All @@ -202,7 +199,7 @@ export class HttpFranceTravailGateway implements FranceTravailGateway {
},
});

notifyDiscord(
notifyTeam(
`HttpFranceTravailGateway noResponseInAxiosError ${
ftConvention.originalId
}: ${JSON.stringify(error)}`,
Expand Down Expand Up @@ -255,7 +252,7 @@ export class HttpFranceTravailGateway implements FranceTravailGateway {
},
};
logger.error(errorObject);
notifyObjectDiscord(errorObject);
notifyObjectToTeam(errorObject);

return {
status: error.response.status,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
OpacifiedLogger,
createLogger,
} from "../../../../../../utils/logger";
import { notifyObjectDiscord } from "../../../../../../utils/notifyDiscord";
import { notifyObjectToTeam } from "../../../../../../utils/notifyTeam";
import { parseZodSchemaAndLogErrorOnParsingFailure } from "../../../../../../utils/schema.utils";
import { AccessTokenDto } from "../../dto/AccessToken.dto";
import { FtConnectAdvisorDto } from "../../dto/FtConnectAdvisor.dto";
Expand Down Expand Up @@ -141,7 +141,7 @@ export class HttpFtConnectGateway implements FtConnectGateway {
(error) => {
log.error({ error });
},
(payload) => notifyDiscordOnNotError(payload),
(payload) => notifyTeamOnNotError(payload),
);
return manageFtConnectError(error, "exchangeCodeForAccessToken", {
authorization: authorizationCode,
Expand Down Expand Up @@ -215,7 +215,7 @@ export class HttpFtConnectGateway implements FtConnectGateway {
(error) => {
log.error({ error });
},
(payload) => notifyDiscordOnNotError(payload),
(payload) => notifyTeamOnNotError(payload),
);
return error instanceof ZodError
? false
Expand Down Expand Up @@ -256,7 +256,7 @@ export class HttpFtConnectGateway implements FtConnectGateway {
(error) => {
log.error({ error });
},
(payload) => notifyDiscordOnNotError(payload),
(payload) => notifyTeamOnNotError(payload),
);
if (error instanceof ZodError) return undefined;
return manageFtConnectError(error, "getUserInfo", {
Expand Down Expand Up @@ -297,11 +297,11 @@ export class HttpFtConnectGateway implements FtConnectGateway {
(error) => {
log.error({ error });
},
(payload) => notifyDiscordOnNotError(payload),
(payload) => notifyTeamOnNotError(payload),
);
if (error instanceof ZodError) return [];
if (isJobseekerButNoAdvisorsResponse(error)) {
notifyObjectDiscord({
notifyObjectToTeam({
message: `isJobseekerButNoAdvisorsResponse for token: ${headers.Authorization}`,
error,
});
Expand Down Expand Up @@ -347,8 +347,8 @@ const errorChecker = (
cbOnNotError: (stuff: unknown) => void,
): void => (error instanceof Error ? cbOnError(error) : cbOnNotError(error));

const notifyDiscordOnNotError = (payload: unknown): void =>
notifyObjectDiscord({
const notifyTeamOnNotError = (payload: unknown): void =>
notifyObjectToTeam({
message: "Should have been an error.",
payload,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
frontRoutes,
queryParamsAsString,
} from "shared";
import { notifyDiscord } from "../../../../../utils/notifyDiscord";
import { notifyTeam } from "../../../../../utils/notifyTeam";
import {
AgencyRightOfUser,
removeAgencyRightsForUser,
Expand Down Expand Up @@ -148,7 +148,7 @@ export class AuthenticateWithInclusionCode extends TransactionalUseCase<
};

if (!newOrUpdatedAuthenticatedUser.externalId) {
notifyDiscord(
notifyTeam(
`Usecase AuthenticateWithInclusionCode. No ongoing_oauths found for externalId:
${newOrUpdatedAuthenticatedUser.id}`,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
LoggerParamsWithMessage,
createLogger,
} from "../../../../utils/logger";
import { notifyObjectDiscord } from "../../../../utils/notifyDiscord";
import { notifyObjectToTeam } from "../../../../utils/notifyTeam";
import { UnitOfWorkPerformer } from "../../unit-of-work/ports/UnitOfWorkPerformer";
import { DomainEvent, EventStatus } from "../events";
import { EventBus } from "../ports/EventBus";
Expand Down Expand Up @@ -36,7 +36,7 @@ export class BasicEventCrawler implements EventCrawler {
message: `${status} outbox ${count} exceeds ${limit}`,
};
logger.error(params);
notifyObjectDiscord(params);
notifyObjectToTeam(params);
}

public async processNewEvents(): Promise<void> {
Expand Down Expand Up @@ -104,7 +104,7 @@ export class BasicEventCrawler implements EventCrawler {
message: "Processing event group is taking long",
events: eventGroup,
};
notifyObjectDiscord(warning);
notifyObjectToTeam(warning);
logger.warn(warning);
}, 30_000);

Expand Down Expand Up @@ -135,7 +135,7 @@ export class BasicEventCrawler implements EventCrawler {
};

logger.error(params);
notifyObjectDiscord({
notifyObjectToTeam({
params,
});

Expand Down
4 changes: 2 additions & 2 deletions back/src/domains/core/events/adapters/InMemoryEventBus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as Sentry from "@sentry/node";
import { keys, prop } from "ramda";
import { DateString, errorToString } from "shared";
import { createLogger } from "../../../../utils/logger";
import { notifyObjectDiscord } from "../../../../utils/notifyDiscord";
import { notifyObjectToTeam } from "../../../../utils/notifyTeam";
import { TimeGateway } from "../../time-gateway/ports/TimeGateway";
import { UnitOfWorkPerformer } from "../../unit-of-work/ports/UnitOfWorkPerformer";
import {
Expand Down Expand Up @@ -118,7 +118,7 @@ export class InMemoryEventBus implements EventBus {
const message = "Failed too many times, event will be Quarantined";
logger.error({ events: [event], message });
const { payload: _, publications: __, ...restEvent } = event;
notifyObjectDiscord({
notifyObjectToTeam({
event: {
...restEvent,
lastPublication: getLastPublication(event),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
jsonStripNulls,
} from "../../../config/pg/kysely/kyselyUtils";
import { createLogger } from "../../../utils/logger";
import { notifyObjectDiscord } from "../../../utils/notifyDiscord";
import { notifyObjectToTeam } from "../../../utils/notifyTeam";
import { FormEstablishmentRepository } from "../ports/FormEstablishmentRepository";

const logger = createLogger(__filename);
Expand Down Expand Up @@ -58,7 +58,7 @@ export class PgFormEstablishmentRepository
message: "Cannot save form establishment ",
error: castedError,
});
notifyObjectDiscord({
notifyObjectToTeam({
_message: `Cannot create form establishment with siret ${formEstablishment.siret}`,
...castedError,
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createAxiosInstance } from "../../../../utils/axiosUtils";
import { createLogger } from "../../../../utils/logger";
import { notifyAndThrowErrorDiscord } from "../../../../utils/notifyDiscord";
import { notifyToTeamAndThrowError } from "../../../../utils/notifyTeam";
import {
PassEmploiGateway,
PassEmploiNotificationParams,
Expand All @@ -26,7 +26,7 @@ export class HttpPassEmploiGateway implements PassEmploiGateway {
});

if (response.status !== 202) {
notifyAndThrowErrorDiscord(
notifyToTeamAndThrowError(
new Error(
`Could not notify Pass-Emploi : ${response.status} ${response.statusText}`,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
errors,
normalizedMonthInDays,
} from "shared";
import { notifyAndThrowErrorDiscord } from "../../../utils/notifyDiscord";
import { notifyToTeamAndThrowError } from "../../../utils/notifyTeam";
import { TransactionalUseCase } from "../../core/UseCase";
import { makeProvider } from "../../core/authentication/inclusion-connect/port/OAuthGateway";
import { CreateNewEvent } from "../../core/events/ports/EventBus";
Expand Down Expand Up @@ -106,7 +106,7 @@ export class ContactEstablishment extends TransactionalUseCase<ContactEstablishm
)?.appellationLabel;

if (!appellationLabel) {
notifyAndThrowErrorDiscord(
notifyToTeamAndThrowError(
errors.establishment.offerMissing({
siret,
appellationCode: contactRequest.appellationCode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
withFormEstablishmentSchema,
} from "shared";
import { rawAddressToLocation } from "../../../utils/address";
import { notifyAndThrowErrorDiscord } from "../../../utils/notifyDiscord";
import { notifyToTeamAndThrowError } from "../../../utils/notifyTeam";
import { getNafAndNumberOfEmployee } from "../../../utils/siret";
import { TransactionalUseCase } from "../../core/UseCase";
import { AddressGateway } from "../../core/address/ports/AddressGateway";
Expand Down Expand Up @@ -110,7 +110,7 @@ export class InsertEstablishmentAggregateFromForm extends TransactionalUseCase<
await uow.establishmentAggregateRepository
.insertEstablishmentAggregate(establishmentAggregate)
.catch((err) => {
notifyAndThrowErrorDiscord(
notifyToTeamAndThrowError(
new Error(
`Error when adding establishment aggregate with siret ${formEstablishment.siret} due to ${err}`,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
legacyContactEstablishmentRequestSchema,
normalizedMonthInDays,
} from "shared";
import { notifyAndThrowErrorDiscord } from "../../../utils/notifyDiscord";
import { notifyToTeamAndThrowError } from "../../../utils/notifyTeam";
import { TransactionalUseCase } from "../../core/UseCase";
import { makeProvider } from "../../core/authentication/inclusion-connect/port/OAuthGateway";
import { CreateNewEvent } from "../../core/events/ports/EventBus";
Expand Down Expand Up @@ -100,7 +100,7 @@ export class LegacyContactEstablishment extends TransactionalUseCase<LegacyConta
)?.appellationLabel;

if (!appellationLabel) {
notifyAndThrowErrorDiscord(
notifyToTeamAndThrowError(
errors.establishment.offerMissing({
appellationCode: contactRequest.appellationCode,
siret,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
immersionFacileNoReplyEmailSender,
siretSchema,
} from "shared";
import { notifyObjectDiscord } from "../../../utils/notifyDiscord";
import { notifyObjectToTeam } from "../../../utils/notifyTeam";
import { TransactionalUseCase } from "../../core/UseCase";
import { makeProvider } from "../../core/authentication/inclusion-connect/port/OAuthGateway";
import { GenerateEditFormEstablishmentJwt } from "../../core/jwt";
Expand Down Expand Up @@ -82,6 +82,6 @@ export class SuggestEditEstablishment extends TransactionalUseCase<SiretDto> {
followedIds: {
establishmentSiret: siret,
},
}).catch((error) => notifyObjectDiscord(error));
}).catch((error) => notifyObjectToTeam(error));
}
}
63 changes: 0 additions & 63 deletions back/src/utils/notifyDiscord.ts

This file was deleted.

Loading

0 comments on commit 586bf93

Please sign in to comment.