Skip to content

Commit

Permalink
send notifications to Slack
Browse files Browse the repository at this point in the history
  • Loading branch information
celineung committed Jan 22, 2025
1 parent d7ff4a8 commit 4a3cd92
Show file tree
Hide file tree
Showing 13 changed files with 84 additions and 2 deletions.
2 changes: 2 additions & 0 deletions back/src/config/helpers/handleHttpJsonResponseError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { HttpError, HttpErrorResponseBody } from "shared";
import { ZodError } from "zod";
import { LoggerParamsWithMessage, createLogger } from "../../utils/logger";
import { notifyObjectDiscord } from "../../utils/notifyDiscord";
import { notifyObjectSlack } from "../../utils/notifySlack";

const logger = createLogger(__filename);

Expand Down Expand Up @@ -106,4 +107,5 @@ const logErrorAndNotifyDiscord = (

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

export const jsonBuildObject = <O extends Record<string, Expression<unknown>>>(
Expand Down Expand Up @@ -64,6 +65,7 @@ export const makeKyselyDb = (pool: Pool, options?: KyselyOptions): KyselyDb => {
},
};
notifyObjectDiscord(params);
notifyObjectSlack(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 @@ -20,6 +20,7 @@ import {
notifyDiscord,
notifyObjectDiscord,
} from "../../../../utils/notifyDiscord";
import { notifyObjectSlack, notifySlack } from "../../../../utils/notifySlack";
import { InMemoryCachingGateway } from "../../../core/caching-gateway/adapters/InMemoryCachingGateway";
import {
RetryStrategy,
Expand Down Expand Up @@ -180,6 +181,11 @@ export class HttpFranceTravailGateway implements FranceTravailGateway {
ftConvention.originalId
}: ${JSON.stringify(error)}`,
);
notifySlack(
`HttpFranceTravailGateway notAxiosError ${
ftConvention.originalId
}: ${JSON.stringify(error)}`,
);

return {
status: 500,
Expand Down Expand Up @@ -207,6 +213,11 @@ export class HttpFranceTravailGateway implements FranceTravailGateway {
ftConvention.originalId
}: ${JSON.stringify(error)}`,
);
notifySlack(
`HttpFranceTravailGateway noResponseInAxiosError ${
ftConvention.originalId
}: ${JSON.stringify(error)}`,
);

return {
status: 500,
Expand Down Expand Up @@ -256,6 +267,7 @@ export class HttpFranceTravailGateway implements FranceTravailGateway {
};
logger.error(errorObject);
notifyObjectDiscord(errorObject);
notifyObjectSlack(errorObject);

return {
status: error.response.status,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
createLogger,
} from "../../../../../../utils/logger";
import { notifyObjectDiscord } from "../../../../../../utils/notifyDiscord";
import { notifyObjectSlack } from "../../../../../../utils/notifySlack";
import { parseZodSchemaAndLogErrorOnParsingFailure } from "../../../../../../utils/schema.utils";
import { AccessTokenDto } from "../../dto/AccessToken.dto";
import { FtConnectAdvisorDto } from "../../dto/FtConnectAdvisor.dto";
Expand Down Expand Up @@ -305,6 +306,10 @@ export class HttpFtConnectGateway implements FtConnectGateway {
message: `isJobseekerButNoAdvisorsResponse for token: ${headers.Authorization}`,
error,
});
notifyObjectSlack({
message: `isJobseekerButNoAdvisorsResponse for token: ${headers.Authorization}`,
error,
});
return [];
}
return manageFtConnectError(error, "getAdvisorsInfo", {
Expand Down Expand Up @@ -347,11 +352,16 @@ const errorChecker = (
cbOnNotError: (stuff: unknown) => void,
): void => (error instanceof Error ? cbOnError(error) : cbOnNotError(error));

const notifyDiscordOnNotError = (payload: unknown): void =>
const notifyDiscordOnNotError = (payload: unknown): void => {
notifyObjectDiscord({
message: "Should have been an error.",
payload,
});
notifyObjectSlack({
message: "Should have been an error.",
payload,
});
};

const isJobSeekerFromStatus = (codeStatutIndividu: "0" | "1"): boolean =>
codeStatutIndividu === "1";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
queryParamsAsString,
} from "shared";
import { notifyDiscord } from "../../../../../utils/notifyDiscord";
import { notifySlack } from "../../../../../utils/notifySlack";
import {
AgencyRightOfUser,
removeAgencyRightsForUser,
Expand Down Expand Up @@ -152,6 +153,10 @@ export class AuthenticateWithInclusionCode extends TransactionalUseCase<
`Usecase AuthenticateWithInclusionCode. No ongoing_oauths found for externalId:
${newOrUpdatedAuthenticatedUser.id}`,
);
notifySlack(
`Usecase AuthenticateWithInclusionCode. No ongoing_oauths found for externalId:
${newOrUpdatedAuthenticatedUser.id}`,
);
}

await uow.userRepository.save(newOrUpdatedAuthenticatedUser, provider);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
createLogger,
} from "../../../../utils/logger";
import { notifyObjectDiscord } from "../../../../utils/notifyDiscord";
import { notifyObjectSlack } from "../../../../utils/notifySlack";
import { UnitOfWorkPerformer } from "../../unit-of-work/ports/UnitOfWorkPerformer";
import { DomainEvent, EventStatus } from "../events";
import { EventBus } from "../ports/EventBus";
Expand Down Expand Up @@ -37,6 +38,7 @@ export class BasicEventCrawler implements EventCrawler {
};
logger.error(params);
notifyObjectDiscord(params);
notifyObjectSlack(params);
}

public async processNewEvents(): Promise<void> {
Expand Down Expand Up @@ -105,6 +107,7 @@ export class BasicEventCrawler implements EventCrawler {
events: eventGroup,
};
notifyObjectDiscord(warning);
notifyObjectSlack(warning);
logger.warn(warning);
}, 30_000);

Expand Down Expand Up @@ -138,6 +141,9 @@ export class BasicEventCrawler implements EventCrawler {
notifyObjectDiscord({
params,
});
notifyObjectSlack({
params,
});

return [];
});
Expand Down
8 changes: 8 additions & 0 deletions back/src/domains/core/events/adapters/InMemoryEventBus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { keys, prop } from "ramda";
import { DateString, errorToString } from "shared";
import { createLogger } from "../../../../utils/logger";
import { notifyObjectDiscord } from "../../../../utils/notifyDiscord";
import { notifyObjectSlack } from "../../../../utils/notifySlack";
import { TimeGateway } from "../../time-gateway/ports/TimeGateway";
import { UnitOfWorkPerformer } from "../../unit-of-work/ports/UnitOfWorkPerformer";
import {
Expand Down Expand Up @@ -125,6 +126,13 @@ export class InMemoryEventBus implements EventBus {
},
message,
});
notifyObjectSlack({
event: {
...restEvent,
lastPublication: getLastPublication(event),
},
message,
});
}

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
} from "../../../config/pg/kysely/kyselyUtils";
import { createLogger } from "../../../utils/logger";
import { notifyObjectDiscord } from "../../../utils/notifyDiscord";
import { notifyObjectSlack } from "../../../utils/notifySlack";
import { FormEstablishmentRepository } from "../ports/FormEstablishmentRepository";

const logger = createLogger(__filename);
Expand Down Expand Up @@ -62,6 +63,10 @@ export class PgFormEstablishmentRepository
_message: `Cannot create form establishment with siret ${formEstablishment.siret}`,
...castedError,
});
notifyObjectSlack({
_message: `Cannot create form establishment with siret ${formEstablishment.siret}`,
...castedError,
});

throw errors.establishment.pgCreateConflict({
siret: formEstablishment.siret,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { createAxiosInstance } from "../../../../utils/axiosUtils";
import { createLogger } from "../../../../utils/logger";
import { notifyAndThrowErrorDiscord } from "../../../../utils/notifyDiscord";
import { notifyAndThrowErrorSlack } from "../../../../utils/notifySlack";
import {
PassEmploiGateway,
PassEmploiNotificationParams,
Expand Down Expand Up @@ -31,6 +32,11 @@ export class HttpPassEmploiGateway implements PassEmploiGateway {
`Could not notify Pass-Emploi : ${response.status} ${response.statusText}`,
),
);
notifyAndThrowErrorSlack(
new Error(
`Could not notify Pass-Emploi : ${response.status} ${response.statusText}`,
),
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
normalizedMonthInDays,
} from "shared";
import { notifyAndThrowErrorDiscord } from "../../../utils/notifyDiscord";
import { notifyAndThrowErrorSlack } from "../../../utils/notifySlack";
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 @@ -113,6 +114,13 @@ export class ContactEstablishment extends TransactionalUseCase<ContactEstablishm
mode: "bad request",
}),
);
notifyAndThrowErrorSlack(
errors.establishment.offerMissing({
siret,
appellationCode: contactRequest.appellationCode,
mode: "bad request",
}),
);

// we keep discord notification for now, but we will remove it when the bug is confirmed and fixed
// Than it will just be :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
} from "shared";
import { rawAddressToLocation } from "../../../utils/address";
import { notifyAndThrowErrorDiscord } from "../../../utils/notifyDiscord";
import { notifyAndThrowErrorSlack } from "../../../utils/notifySlack";
import { getNafAndNumberOfEmployee } from "../../../utils/siret";
import { TransactionalUseCase } from "../../core/UseCase";
import { AddressGateway } from "../../core/address/ports/AddressGateway";
Expand Down Expand Up @@ -115,6 +116,11 @@ export class InsertEstablishmentAggregateFromForm extends TransactionalUseCase<
`Error when adding establishment aggregate with siret ${formEstablishment.siret} due to ${err}`,
),
);
notifyAndThrowErrorSlack(
new Error(
`Error when adding establishment aggregate with siret ${formEstablishment.siret} due to ${err}`,
),
);
});

const event = this.createNewEvent({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
normalizedMonthInDays,
} from "shared";
import { notifyAndThrowErrorDiscord } from "../../../utils/notifyDiscord";
import { notifyAndThrowErrorSlack } from "../../../utils/notifySlack";
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 @@ -107,6 +108,13 @@ export class LegacyContactEstablishment extends TransactionalUseCase<LegacyConta
mode: "bad request",
}),
);
notifyAndThrowErrorSlack(
errors.establishment.offerMissing({
appellationCode: contactRequest.appellationCode,
siret,
mode: "bad request",
}),
);

// we keep discord notification for now, but we will remove it when the bug is confirmed and fixed
// Than it will just be :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
siretSchema,
} from "shared";
import { notifyObjectDiscord } from "../../../utils/notifyDiscord";
import { notifyObjectSlack } from "../../../utils/notifySlack";
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 +83,9 @@ export class SuggestEditEstablishment extends TransactionalUseCase<SiretDto> {
followedIds: {
establishmentSiret: siret,
},
}).catch((error) => notifyObjectDiscord(error));
}).catch((error) => {
notifyObjectDiscord(error);
notifyObjectSlack(error);
});
}
}

0 comments on commit 4a3cd92

Please sign in to comment.