Skip to content

Commit

Permalink
eror handling
Browse files Browse the repository at this point in the history
  • Loading branch information
meseven committed Dec 10, 2017
1 parent 5025fa9 commit 569992e
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 43 deletions.
131 changes: 92 additions & 39 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 12 additions & 1 deletion express/middleware/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,20 @@ const app = express();
const user = require('./routes/user');
const profile = require('./routes/profile');

app.set('view engine', 'pug');

app.use('/user', user);
app.use('/profile', profile);

app.use((err, req, res, next) => {
res.status(err.status);
res.render('error', {
message: err.message,
status: err.status
});
});

app.listen(3000, () => {
console.log("express server çalıştı.");
});
});

2 changes: 1 addition & 1 deletion express/middleware/helper/isLogin.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const isLogin = (req, res, next) => {
const isLogin = false;
const isLogin = true;

if (isLogin)
next();
Expand Down
9 changes: 7 additions & 2 deletions express/middleware/routes/user.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
const express = require('express');
const router = express.Router();

router.get('/', (req, res) => {
res.send("user sayfası");
router.get('/', (req, res, next) => {
const user = false;

if (user)
res.send("user sayfası");
else
return next({ status: 404, message: "Bu kullanıcı bulunamadı" });
});

module.exports = router;
3 changes: 3 additions & 0 deletions express/middleware/views/error.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
h1=status
p
h3=message

0 comments on commit 569992e

Please sign in to comment.