diff --git a/src/controllers/places/delete_place.js b/src/controllers/places/delete_place.js index 962eaaf..aab3b18 100644 --- a/src/controllers/places/delete_place.js +++ b/src/controllers/places/delete_place.js @@ -9,10 +9,16 @@ module.exports = (req, res) => { Request(reqOptions, (error, response) => { if (error) { - res.status(400).send(error); + return res.render('error', { + statusCode: 500, + errorMessage: res.locals.localText.serverError + }); } if (response.statusCode !== 204) { - return res.status(400).send(error); + return res.render('error', { + statusCode: 400, + errorMessage: res.locals.localText.badRequest + }); } else { res.redirect(`/${req.params.lang}/places`); } diff --git a/src/controllers/places/get_all.js b/src/controllers/places/get_all.js index 5ae9f8a..cdd0477 100644 --- a/src/controllers/places/get_all.js +++ b/src/controllers/places/get_all.js @@ -4,10 +4,16 @@ const { placesURL } = require('../../constants/urls.json'); module.exports = (req, res) => { Request(placesURL, (error, response, body) => { if (error) { - res.status(400).send(error); + return res.render('error', { + statusCode: 500, + errorMessage: res.locals.localText.serverError + }); } if (response.statusCode !== 200) { - return res.status(400).send(error); + return res.render('error', { + statusCode: 400, + errorMessage: res.locals.localText.badRequest + }); } const data = JSON.parse(body).filter((place) => { diff --git a/src/controllers/places/get_specific.js b/src/controllers/places/get_specific.js index 3d592a2..7632e9d 100644 --- a/src/controllers/places/get_specific.js +++ b/src/controllers/places/get_specific.js @@ -4,10 +4,16 @@ const { placesURL } = require('../../constants/urls.json'); module.exports = (req, res) => { Request(`${placesURL}/${req.params.id}`, (error, response, body) => { if (error) { - res.status(400).send(error); + return res.render('error', { + statusCode: 500, + errorMessage: res.locals.localText.serverError + }); } if (response.statusCode !== 200) { - return res.status(400).send(error); + res.render('error', { + statusCode: 400, + errorMessage: res.locals.localText.badRequest + }); } const place = JSON.parse(body); diff --git a/src/controllers/places/modify_content.js b/src/controllers/places/modify_content.js index 790d3a9..aaa8e51 100644 --- a/src/controllers/places/modify_content.js +++ b/src/controllers/places/modify_content.js @@ -51,7 +51,10 @@ module.exports = (req, res) => { correctResponseStatusCode = 200; break; default: - res.status(500).send('server error'); + return res.render('error', { + statusCode: 500, + errorMessage: res.locals.localText.serverError + }); } const reqOptions = { @@ -62,10 +65,16 @@ module.exports = (req, res) => { }; Request(reqOptions, (error, apiResponse, apiResponseBody) => { if (error) { - res.status(400).send('server error'); + res.render('error', { + statusCode: 500, + errorMessage: res.locals.localText.serverError + }); } if (apiResponse.statusCode !== correctResponseStatusCode) { - res.status(400).send(apiResponseBody); + return res.render('error', { + statusCode: 400, + errorMessage: res.locals.localText.badRequest + }); } else { res.redirect(`/${req.params.lang}/${urlEndpoint}`); } diff --git a/src/controllers/places/render_edit_form.js b/src/controllers/places/render_edit_form.js index 662b844..d48fdd9 100644 --- a/src/controllers/places/render_edit_form.js +++ b/src/controllers/places/render_edit_form.js @@ -4,10 +4,16 @@ const { placesURL } = require('../../constants/urls.json'); module.exports = (req, res) => { Request(`${placesURL}/${req.params.id}`, (error, response, body) => { if (error) { - res.status(400).send(error); + return res.render('error', { + statusCode: 500, + errorMessage: res.locals.localText.serverError + }); } if (response.statusCode !== 200) { - return res.status(400).send(error); + res.render('error', { + statusCode: 400, + errorMessage: res.locals.localText.badRequest + }); } const place = JSON.parse(body); diff --git a/src/middleware/langError.js b/src/middleware/langError.js index 332d916..98afc89 100644 --- a/src/middleware/langError.js +++ b/src/middleware/langError.js @@ -6,7 +6,10 @@ module.exports = (req, res, next) => { if (path === '/') { return next(); } else { - return res.status(404).send('Page does not exist'); + return res.render('error', { + statusCode: 404, + errorMessage: res.local.localText.notFound + }); } } next(); diff --git a/src/text.js b/src/text.js index cb219e0..f85c167 100644 --- a/src/text.js +++ b/src/text.js @@ -4,6 +4,10 @@ module.exports = { homePage: 'Home Page', english: 'English', arabic: 'Arabic', + error: 'Error', + serverError: 'Server error', + badRequest: 'Bad Request', + notFound: 'Page not found', backList: 'Back to list', placeFormInfo: 'Details below are required in at least one of Arabic and English.', placesTitle: 'Places', @@ -55,6 +59,10 @@ module.exports = { homePage: 'الصفحة الرئيسية', english: 'الانجليزية', arabic: 'العربية', + error: 'خطأ', + serverError: 'خطأ في الخادم', + badRequest: 'خطأ في ارسال الطلب', + notFound: 'لم يتم ايجاد الصفحة', backList: 'عودة الى القائمة', placeFormInfo: 'التفاصيل ادناه مطلوبة على الاقل في واحدة من اللغتين العربية اوالانجليزية', placesTitle: 'أماكن', diff --git a/views/error.hbs b/views/error.hbs new file mode 100644 index 0000000..eff34ed --- /dev/null +++ b/views/error.hbs @@ -0,0 +1,3 @@ +
+

{{localText.error}} {{statusCode}} - {{errorMessage}}

+