Skip to content

Commit

Permalink
add error handle
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafe committed Jul 27, 2012
1 parent e6d695e commit 49b8efa
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
8 changes: 7 additions & 1 deletion app.coffee
Expand Up @@ -56,11 +56,17 @@ app.get '/create', (req, res)->
app.get /^\/([a-zA-Z0-9]{1,5})$/, (req, res, next)->
code = req.params[0]
client.get "url:#{code}", (err, reply)->
return next(err) if err
return next(err) if err or not reply
log.info "redirect user to #{reply}"
client.hincrby 'hits', reply, 1
res.redirect reply

app.use (err, req, res, next)->
if process.env.NODE_ENV is 'production'
res.render '404'
else
next(err)

log.info "start #{process.env.NODE_ENV} server with #{port}"
app.listen port

Expand Down
6 changes: 6 additions & 0 deletions views/404.jade
@@ -0,0 +1,6 @@
extends layout

block content
.container
.hero-unit
h1 Sorry, Something went wrong on this address

0 comments on commit 49b8efa

Please sign in to comment.