Skip to content

Commit

Permalink
add log to troubleshoot pe broacast
Browse files Browse the repository at this point in the history
  • Loading branch information
bbohec committed Jul 5, 2023
1 parent 3e4bb6c commit b08c682
Showing 1 changed file with 45 additions and 3 deletions.
48 changes: 45 additions & 3 deletions back/src/adapters/secondary/poleEmploi/HttpPoleEmploiGateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,26 +45,68 @@ export class HttpPoleEmploiGateway implements PoleEmploiGateway {
public async notifyOnConventionUpdated(
poleEmploiConvention: PoleEmploiConvention,
): Promise<PoleEmploiBroadcastResponse> {
logger.info({
_title: "PeBroadcast",
status: "start",
peConvention: {
peId: poleEmploiConvention.id,
originalId: poleEmploiConvention.originalId,
},
});
return this.postPoleEmploiConvention(poleEmploiConvention)
.then((response) => ({ status: response.status as 200 | 201 }))
.then((response) => {
logger.info({
_title: "PeBroadcast",
status: "success",
httpStatus: response.status,
peConvention: {
peId: poleEmploiConvention.id,
originalId: poleEmploiConvention.originalId,
},
});
return { status: response.status as 200 | 201 };
})
.catch((error) => {
if (!axios.isAxiosError(error) || !error.response) {
logger.error({
_title: "PeBroadcast",
status: "notAxiosErrorOrNoResponse",
error,
peConvention: {
peId: poleEmploiConvention.id,
originalId: poleEmploiConvention.originalId,
},
});
throw error;
}

if (error.response.status === 404) {
logger.error({
_title: "PeBroadcast",
status: "notFoundOrMismatch",
httpStatus: error.response.status,
message: error.response.data?.message,
peConvention: {
peId: poleEmploiConvention.id,
originalId: poleEmploiConvention.originalId,
},
});
return {
status: 404,
message: error.response.data?.message,
};
}

const errorObject = {
_title: "PeBroadcastError",
status: "errored",
_title: "PeBroadcast",
status: "unknownAxiosError",
httpStatus: error.response.status,
message: error.message,
axiosBody: error.response.data,
peConvention: {
peId: poleEmploiConvention.id,
originalId: poleEmploiConvention.originalId,
},
};
logger.error(errorObject);
notifyObjectDiscord(errorObject);
Expand Down

0 comments on commit b08c682

Please sign in to comment.