From 68f92c41b87745cb02807913866420079ee5f757 Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Wed, 20 Sep 2023 13:53:21 +0100 Subject: [PATCH] Update the error handling data for ldb API responses. Signed-off-by: Fred Boniface --- src/configs/errorCodes.configs.ts | 9 +++++++-- src/services/ldb.services.js | 5 +++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/configs/errorCodes.configs.ts b/src/configs/errorCodes.configs.ts index f9956b3..d35f281 100644 --- a/src/configs/errorCodes.configs.ts +++ b/src/configs/errorCodes.configs.ts @@ -1,6 +1,6 @@ // statusCodes should be a map, not an object -const statusCodes = { +export const statusCodes = { 400: "data not found", 700: "no authentication attempt", 701: "invalid credentials", @@ -14,5 +14,10 @@ const statusCodes = { 951: "unknown server error", }; +export const msgCodes = new Map ([ + ["LOC_NOT_FOUND", "Location not found. If you are sure that the location exists, there may be a fault with the data provider."], + ["AUTH_ERR", "Authentication Error"], +]) + module.exports = statusCodes; -export { statusCodes }; +//export { statusCodes }; diff --git a/src/services/ldb.services.js b/src/services/ldb.services.js index 37c0291..1f83126 100644 --- a/src/services/ldb.services.js +++ b/src/services/ldb.services.js @@ -7,6 +7,7 @@ const san = require("../utils/sanitizer.utils"); const db = require("../services/dbAccess.services"); import { transform as staffStationTransform } from "../utils/translators/ldb/staffStation"; +import { msgCodes } from "../configs/errorCodes.configs"; const ldbKey = process.env.OWL_LDB_KEY; const ldbsvKey = process.env.OWL_LDB_SVKEY; @@ -29,8 +30,8 @@ async function get(id, staff = false) { } catch (err) { log.out(`ldbService.get: Error, Unable to find CRS: ${err}`, "info"); return { - ERROR: "NOT_FOUND", - description: "The entered station was not found.", + obStatus: "LOC_NOT_FOUND", + obMsg: msgCodes.get(this.obStatus), }; } }