From c59fd65155a8005f28a3d16778373bc23ee25a38 Mon Sep 17 00:00:00 2001 From: Carson Fleming Date: Sat, 21 Oct 2023 01:53:43 -0400 Subject: Create UX contingencies for malformed URLs and slugs --- routes.js | 6 +++--- utils.js | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/routes.js b/routes.js index 207a022..ec333ec 100644 --- a/routes.js +++ b/routes.js @@ -7,13 +7,13 @@ const router = express.Router(); async function createRoute(res, url, slug) { try { if (!utils.isUrlFormatted(url)) - return utils.sendBadRequestError(res, 'URL "'+url+'" is malformatted. Must be a valid URL.'); + return utils.sendBadRequestError(res, 'URL "'+url+'" is malformatted. Must be a valid URL.', 'Malformed URL'); if (!utils.isAlphaNumeric(slug)) - return utils.sendBadRequestError(res, 'Slug "'+slug+'" is malformatted. Must be alphanumeric.'); + return utils.sendBadRequestError(res, 'Slug "'+slug+'" is malformatted. Must be alphanumeric.', 'Malformed Short URL'); slug = slug.toLowerCase(); if (await Url.exists({slug: slug})) - return utils.sendBadRequestError(res, 'Slug "'+slug+'" already exists. Updates are not supported at this time.'); + return utils.sendBadRequestError(res, 'Slug "'+slug+'" already exists. Updates are not supported at this time.', 'Already Exists'); await new Url({url, slug}).save(); utils.sendSuccessfulSlugCreation(res, slug); diff --git a/utils.js b/utils.js index 695063f..1fc17c6 100644 --- a/utils.js +++ b/utils.js @@ -24,8 +24,8 @@ const helperFunctions = { else res.send(JSON.stringify(statusJson)); }); }, - sendBadRequestError : function (res, errorMessage) { - res.status(400).json({status: "ERROR", statusCode: 400, errorType: "BAD REQUEST", errorMessage, uiString: "Already Exists"}); + sendBadRequestError : function (res, errorMessage, uiString) { + res.status(400).json({status: "ERROR", statusCode: 400, errorType: "BAD REQUEST", errorMessage, uiString}); }, sendInternalServerError : function (res, error) { console.error('[express] Error:', error); -- cgit v1.2.3