Skip to content

Commit

Permalink
chore: Improve Unifrom error logging
Browse files Browse the repository at this point in the history
  • Loading branch information
DafyddLlyr committed Oct 18, 2023
1 parent d86cd87 commit 82a8f24
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions api.planx.uk/send/uniform.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import axios, { AxiosRequestConfig } from "axios";
import axios, { AxiosRequestConfig, isAxiosError } from "axios";
import { NextFunction, Request, Response } from "express";
import { Buffer } from "node:buffer";
import FormData from "form-data";
Expand Down Expand Up @@ -157,9 +157,12 @@ export async function sendToUniform(
application: applicationAuditRecord,
});
} catch (error) {
const errorMessage = isAxiosError(error)
? JSON.stringify(error.toJSON())
: (error as Error).message;
return next({
error,
message: `Failed to send to Uniform (${localAuthority}): ${error}`,
message: `Failed to send to Uniform (${localAuthority}): ${errorMessage}`,
});
}
}
Expand Down Expand Up @@ -219,7 +222,13 @@ async function authenticate({
const response = await axios.request<RawUniformAuthResponse>(authConfig);

if (!response.data.access_token) {
throw Error("Failed to authenticate to Uniform");
throw Error("Failed to authenticate to Uniform - no access token returned");
}

if (!response.data["organisation-name"] || response.data["organisation-id"]) {
throw Error(
"Failed to authenticate to Uniform - no organisation details returned",
);
}

const uniformAuthResponse: UniformAuthResponse = {
Expand Down

0 comments on commit 82a8f24

Please sign in to comment.