From 155a3c588ce775c0e3b49c24830d779b10802e7f Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Mon, 10 Apr 2023 20:19:37 +0100 Subject: [PATCH] Add error codes Signed-off-by: Fred Boniface --- .../{statusCodes.configs.js => errorCodes.configs.js} | 2 ++ src/services/registration.services.js | 7 ++++--- 2 files changed, 6 insertions(+), 3 deletions(-) rename src/configs/{statusCodes.configs.js => errorCodes.configs.js} (72%) diff --git a/src/configs/statusCodes.configs.js b/src/configs/errorCodes.configs.js similarity index 72% rename from src/configs/statusCodes.configs.js rename to src/configs/errorCodes.configs.js index ace3c08..88e15d9 100644 --- a/src/configs/statusCodes.configs.js +++ b/src/configs/errorCodes.configs.js @@ -2,7 +2,9 @@ module.exports = statusCodes = { 700: "no authentication attempt", 701: "invalid credentials", 702: "domain whitelisted", + 703: "registration request not found, maybe expired", 800: "location code not found", 801: "unable to fetch location data", 900: "invalid request format", + 950: "upstream server error", } \ No newline at end of file diff --git a/src/services/registration.services.js b/src/services/registration.services.js index dc16afa..6ede7a4 100644 --- a/src/services/registration.services.js +++ b/src/services/registration.services.js @@ -4,6 +4,7 @@ const db = require('./dbAccess.services') const mail = require('./mail.services') const clean = require('../utils/sanitizer.utils') const domains = require('../configs/domains.configs') +const errors = require('../configs/errorCodes.configs') async function createRegKey(body) { log.out(`registerServices.createRegKey: Incoming request`, "INFO") @@ -22,9 +23,9 @@ async function createRegKey(body) { if (await mail.send(message) == true) { return {status: 201, message: "email sent"} } - return {status: 500, message: "server error, email send failed"} + return {status: 500, errorCode: 950, errorMsg: errors[950]} } - return {status: 403, message: "forbidden, domain is not on whitelist"} + return {status: 403, errorCode: 702, errorMsg: errors[702]} } async function regUser(req) { // Add input validation @@ -40,7 +41,7 @@ async function regUser(req) { // Add input validation return {status: 201, message: "User added", api_key: uuid} } } - return {status: 401, message: "Unauthorised"} + return {status: 401, errorCode: 703, errorMsg: errors[703]} } module.exports = {