Skip to content

Commit

Permalink
chore: Improve send to BOPS error messages (#2752)
Browse files Browse the repository at this point in the history
  • Loading branch information
DafyddLlyr authored Feb 5, 2024
1 parent eadbffc commit 92c6339
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 deletions api.planx.uk/modules/send/bops/bops.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ const sendToBOPS = async (req: Request, res: Response, next: NextFunction) => {
const env =
process.env.APP_ENVIRONMENT === "production" ? "production" : "staging";

const { bopsSubmissionURL, bopsToken } = await $api.team.getIntegrations({
slug: localAuthority,
encryptionKey: process.env.ENCRYPTION_KEY!,
env,
});
const target = `${bopsSubmissionURL}/api/v1/planning_applications`;
const exportData = await $api.export.bopsPayload(payload?.sessionId);

try {
const { bopsSubmissionURL, bopsToken } = await $api.team.getIntegrations({
slug: localAuthority,
encryptionKey: process.env.ENCRYPTION_KEY!,
env,
});
const target = `${bopsSubmissionURL}/api/v1/planning_applications`;
const exportData = await $api.export.bopsPayload(payload?.sessionId);

const bopsResponse = await axios({
method: "POST",
url: target,
Expand Down Expand Up @@ -121,7 +121,7 @@ const sendToBOPS = async (req: Request, res: Response, next: NextFunction) => {
error.response.data,
null,
2,
)}`,
)}. Error: ${error}`,
);
} else {
// re-throw other errors
Expand All @@ -135,7 +135,7 @@ const sendToBOPS = async (req: Request, res: Response, next: NextFunction) => {
next(
new ServerError({
status: 500,
message: `Sending to BOPS failed (${localAuthority})`,
message: `Sending to BOPS failed (${localAuthority}). Error ${err}`,
cause: err,
}),
);
Expand Down Expand Up @@ -174,17 +174,18 @@ const sendToBOPSV2 = async (
const localAuthority = req.params.localAuthority;
const env =
process.env.APP_ENVIRONMENT === "production" ? "production" : "staging";
const { bopsSubmissionURL, bopsToken } = await $api.team.getIntegrations({
slug: localAuthority,
encryptionKey: process.env.ENCRYPTION_KEY!,
env,
});
const target = `${bopsSubmissionURL}/api/v2/planning_applications`;
const exportData = await $api.export.digitalPlanningDataPayload(
payload?.sessionId,
);

try {
const { bopsSubmissionURL, bopsToken } = await $api.team.getIntegrations({
slug: localAuthority,
encryptionKey: process.env.ENCRYPTION_KEY!,
env,
});
const target = `${bopsSubmissionURL}/api/v2/planning_applications`;
const exportData = await $api.export.digitalPlanningDataPayload(
payload?.sessionId,
);

const bopsResponse = await axios({
method: "POST",
url: target,
Expand Down Expand Up @@ -269,7 +270,7 @@ const sendToBOPSV2 = async (
payload?.sessionId,
]
.filter(Boolean)
.join(" - ")})`,
.join(" - ")}). Error: ${err}`,
cause: err,
}),
);
Expand Down

0 comments on commit 92c6339

Please sign in to comment.