From 82a8f24d351e55254738efbf480e0f828f07010b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dafydd=20Ll=C5=B7r=20Pearson?= Date: Wed, 18 Oct 2023 12:02:23 +0100 Subject: [PATCH] chore: Improve Unifrom error logging --- api.planx.uk/send/uniform.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/api.planx.uk/send/uniform.ts b/api.planx.uk/send/uniform.ts index 919eb32cba..3fad3a611f 100644 --- a/api.planx.uk/send/uniform.ts +++ b/api.planx.uk/send/uniform.ts @@ -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"; @@ -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}`, }); } } @@ -219,7 +222,13 @@ async function authenticate({ const response = await axios.request(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 = {