34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/closure/show_exceptions.rb', line 34
def call(env)
@app.call(env)
rescue Closure::Compiler::Error => e
raise e unless env[Script::ENV_ERROR_CONTENT_TYPE] == 'application/javascript'
body = 'try{console.error('
body += '"Closure Compiler: %s\n", '
body += "#{e.message.rstrip.dump}"
body += ')}catch(err){}'
[200,
{"Content-Type" => "application/javascript",
"Content-Length" => body.size.to_s},
[body]]
rescue Closure::Templates::Error => e
raise e unless env[Script::ENV_ERROR_CONTENT_TYPE] == 'application/javascript'
body = 'try{console.error('
body += '"Closure Templates: 1 error(s)\n$s", '
body += "#{e.message.rstrip.dump}"
body += ')}catch(err){}'
[200,
{"Content-Type" => "application/javascript",
"Content-Length" => body.size.to_s},
[body]]
rescue StandardError, LoadError, SyntaxError => e
raise e unless env[Script::ENV_ERROR_CONTENT_TYPE] == 'application/javascript'
body = 'try{console.error('
if e.class.to_s == e.message.rstrip
body += '"Closure Script: %s\n%s", '
else
body += '"Closure Script: %s\n\n%s\n\n%s", '
body += "#{e.class.to_s.dump}, "
end
body += "#{e.message.rstrip.dump}, "
body += "#{e.backtrace.join("\n").dump}"
body += ')}catch(err){}'
[200,
{"Content-Type" => "application/javascript",
"Content-Length" => body.size.to_s},
[body]]
end
|