diff options
| author | Carson Fleming <cflems@cflems.net> | 2023-10-21 01:53:43 -0400 |
|---|---|---|
| committer | Carson Fleming <cflems@cflems.net> | 2023-10-21 01:53:43 -0400 |
| commit | c59fd65155a8005f28a3d16778373bc23ee25a38 (patch) | |
| tree | d7ddafc3814d7585d4994a4160fa613abdd71afb | |
| parent | 1f46c091dd4f2e1c2e58f658544a68656fb056e7 (diff) | |
| download | fle.ms-c59fd65155a8005f28a3d16778373bc23ee25a38.tar.gz | |
Create UX contingencies for malformed URLs and slugs
| -rw-r--r-- | routes.js | 6 | ||||
| -rw-r--r-- | utils.js | 4 |
2 files changed, 5 insertions, 5 deletions
@@ -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); @@ -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); |
