LoginSignup
1
1

More than 5 years have passed since last update.

テンプレートエンジンをjadeからectにしてみたらエラーが出なくてつまづいた。(expressのエラーハンドリングについて)

Posted at

error.ectがあるせいでエラーが表示されない。

error.jadeをerror.ectにしておいたものだから、
error.ectが 正常に 表示されている。

extends layout block content h1= message h2= error.status pre #{error.stack}

って表示されるだけでerror内容が不明。

そこで、error.etcの中身もetcの記法に書き換えて…。

error.etc
<% extend 'layout' %>
<%= @message %>

で、エラーが表示されて原因が特定できた。

おまけ

app.jsにerrorハンドリングが以下のように書いてあるから、
console.logとかで出すことも出来る。

myapp/app.js
// development error handler
// will print stacktrace
if (app.get('env') === 'development') {
    app.use(function(err, req, res, next) {
        console.log(err); //追加
        res.status(err.status || 500);
            res.render('error', {
            message: err.message,
            error: err
        });    
    });        
}    

タイトル長いね。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1