Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error page #48

Merged
merged 8 commits into from
Oct 1, 2017
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/controllers/places/delete_place.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
}
Expand Down
10 changes: 8 additions & 2 deletions src/controllers/places/get_all.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
10 changes: 8 additions & 2 deletions src/controllers/places/get_specific.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 9 additions & 3 deletions src/controllers/places/modify_content.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -62,10 +65,13 @@ module.exports = (req, res) => {
};
Request(reqOptions, (error, apiResponse, apiResponseBody) => {
if (error) {
res.status(400).send('server error');
res.render('error');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this one need some parameters passing to it?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jwld maybe @Suuuuha so she sees this? Not sure actually if that helps

}
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}`);
}
Expand Down
10 changes: 8 additions & 2 deletions src/controllers/places/render_edit_form.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 4 additions & 1 deletion src/middleware/langError.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
8 changes: 8 additions & 0 deletions src/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -55,6 +59,10 @@ module.exports = {
homePage: 'الصفحة الرئيسية',
english: 'الانجليزية',
arabic: 'العربية',
error: 'خطأ',
serverError: 'خطأ في الخادم',
badRequest: 'خطأ في ارسال الطلب',
notFound: 'لم يتم ايجاد الصفحة',
backList: 'عودة الى القائمة',
placeFormInfo: 'التفاصيل ادناه مطلوبة على الاقل في واحدة من اللغتين العربية اوالانجليزية',
placesTitle: 'أماكن',
Expand Down
3 changes: 3 additions & 0 deletions views/error.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<section>
<p>{{localText.error}} {{statusCode}} - <span>{{errorMessage}}</span></p>
</section>