Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
a725a453
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
a725a453
编写于
8月 21, 2013
作者:
K
Kir Shatrov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Display exceptions in text format for xhr request
上级
998d9c89
变更
15
隐藏空白更改
内联
并排
Showing
15 changed file
with
129 addition
and
13 deletion
+129
-13
actionpack/CHANGELOG.md
actionpack/CHANGELOG.md
+4
-0
actionpack/lib/action_dispatch/middleware/debug_exceptions.rb
...onpack/lib/action_dispatch/middleware/debug_exceptions.rb
+21
-13
actionpack/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb
...ddleware/templates/rescues/_request_and_response.html.erb
+0
-0
actionpack/lib/action_dispatch/middleware/templates/rescues/_request_and_response.text.erb
...ddleware/templates/rescues/_request_and_response.text.erb
+23
-0
actionpack/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb
...ion_dispatch/middleware/templates/rescues/_trace.html.erb
+0
-0
actionpack/lib/action_dispatch/middleware/templates/rescues/_trace.text.erb
...ion_dispatch/middleware/templates/rescues/_trace.text.erb
+15
-0
actionpack/lib/action_dispatch/middleware/templates/rescues/missing_template.html.erb
...ch/middleware/templates/rescues/missing_template.html.erb
+0
-0
actionpack/lib/action_dispatch/middleware/templates/rescues/missing_template.text.erb
...ch/middleware/templates/rescues/missing_template.text.erb
+3
-0
actionpack/lib/action_dispatch/middleware/templates/rescues/routing_error.html.erb
...patch/middleware/templates/rescues/routing_error.html.erb
+0
-0
actionpack/lib/action_dispatch/middleware/templates/rescues/routing_error.text.erb
...patch/middleware/templates/rescues/routing_error.text.erb
+11
-0
actionpack/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb
...atch/middleware/templates/rescues/template_error.html.erb
+0
-0
actionpack/lib/action_dispatch/middleware/templates/rescues/template_error.text.erb
...atch/middleware/templates/rescues/template_error.text.erb
+8
-0
actionpack/lib/action_dispatch/middleware/templates/rescues/unknown_action.html.erb
...atch/middleware/templates/rescues/unknown_action.html.erb
+0
-0
actionpack/lib/action_dispatch/middleware/templates/rescues/unknown_action.text.erb
...atch/middleware/templates/rescues/unknown_action.text.erb
+3
-0
actionpack/test/dispatch/debug_exceptions_test.rb
actionpack/test/dispatch/debug_exceptions_test.rb
+41
-0
未找到文件。
actionpack/CHANGELOG.md
浏览文件 @
a725a453
*
Development mode exceptions are rendered in text format in case of XHR request.
*Kir Shatrov*
*
Fix an issue where :if and :unless controller action procs were being run
before checking for the correct action in the :only and :unless options.
...
...
actionpack/lib/action_dispatch/middleware/debug_exceptions.rb
浏览文件 @
a725a453
...
...
@@ -34,27 +34,35 @@ def render_exception(env, exception)
log_error
(
env
,
wrapper
)
if
env
[
'action_dispatch.show_detailed_exceptions'
]
request
=
Request
.
new
(
env
)
template
=
ActionView
::
Base
.
new
([
RESCUES_TEMPLATE_PATH
],
:request
=>
Request
.
new
(
env
)
,
:exception
=>
wrapper
.
exception
,
:application_trace
=>
wrapper
.
application_trace
,
:framework_trace
=>
wrapper
.
framework_trace
,
:full_trace
=>
wrapper
.
full_trace
,
:routes_inspector
=>
routes_inspector
(
exception
),
:source_extract
=>
wrapper
.
source_extract
,
:line_number
=>
wrapper
.
line_number
,
:file
=>
wrapper
.
file
request:
request
,
exception:
wrapper
.
exception
,
application_trace:
wrapper
.
application_trace
,
framework_trace:
wrapper
.
framework_trace
,
full_trace:
wrapper
.
full_trace
,
routes_inspector:
routes_inspector
(
exception
),
source_extract:
wrapper
.
source_extract
,
line_number:
wrapper
.
line_number
,
file:
wrapper
.
file
)
file
=
"rescues/
#{
wrapper
.
rescue_template
}
"
body
=
template
.
render
(
:template
=>
file
,
:layout
=>
'rescues/layout'
)
render
(
wrapper
.
status_code
,
body
)
if
request
.
xhr?
body
=
template
.
render
(
template:
file
,
layout:
false
,
formats:
[
:text
])
format
=
"text/plain"
else
body
=
template
.
render
(
template:
file
,
layout:
'rescues/layout'
)
format
=
"text/html"
end
render
(
wrapper
.
status_code
,
body
,
format
)
else
raise
exception
end
end
def
render
(
status
,
body
)
[
status
,
{
'Content-Type'
=>
"
text/html
; charset=
#{
Response
.
default_charset
}
"
,
'Content-Length'
=>
body
.
bytesize
.
to_s
},
[
body
]]
def
render
(
status
,
body
,
format
)
[
status
,
{
'Content-Type'
=>
"
#{
format
}
; charset=
#{
Response
.
default_charset
}
"
,
'Content-Length'
=>
body
.
bytesize
.
to_s
},
[
body
]]
end
def
log_error
(
env
,
wrapper
)
...
...
actionpack/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb
→
actionpack/lib/action_dispatch/middleware/templates/rescues/_request_and_response.
html.
erb
浏览文件 @
a725a453
文件已移动
actionpack/lib/action_dispatch/middleware/templates/rescues/_request_and_response.text.erb
0 → 100644
浏览文件 @
a725a453
<%
clean_params
=
@request
.
filtered_parameters
.
clone
clean_params
.
delete
(
"action"
)
clean_params
.
delete
(
"controller"
)
request_dump
=
clean_params
.
empty?
?
'None'
:
clean_params
.
inspect
.
gsub
(
','
,
",
\n
"
)
def
debug_hash
(
object
)
object
.
to_hash
.
sort_by
{
|
k
,
_
|
k
.
to_s
}.
map
{
|
k
,
v
|
"
#{
k
}
:
#{
v
.
inspect
rescue
$!
.
message
}
"
}.
join
(
"
\n
"
)
end
unless
self
.
class
.
method_defined?
(
:debug_hash
)
%>
Request parameters
<%=
request_dump
%>
Session dump
<%=
debug_hash
@request
.
session
%>
Env dump
<%=
debug_hash
@request
.
env
.
slice
(
*
@request
.
class
::
ENV_METHODS
)
%>
Response headers
<%=
defined?
(
@response
)
?
@response
.
headers
.
inspect
.
gsub
(
','
,
",
\n
"
)
:
'None'
%>
actionpack/lib/action_dispatch/middleware/templates/rescues/_trace.erb
→
actionpack/lib/action_dispatch/middleware/templates/rescues/_trace.
html.
erb
浏览文件 @
a725a453
文件已移动
actionpack/lib/action_dispatch/middleware/templates/rescues/_trace.text.erb
0 → 100644
浏览文件 @
a725a453
<%
traces
=
{
"Application Trace"
=>
@application_trace
,
"Framework Trace"
=>
@framework_trace
,
"Full Trace"
=>
@full_trace
}
%>
Rails.root:
<%=
defined?
(
Rails
)
&&
Rails
.
respond_to?
(
:root
)
?
Rails
.
root
:
"unset"
%>
<%
traces
.
each
do
|
name
,
trace
|
%>
<%
if
trace
.
any?
%>
<%=
name
%>
<%=
trace
.
join
(
"
\n
"
)
%>
<%
end
%>
<%
end
%>
actionpack/lib/action_dispatch/middleware/templates/rescues/missing_template.erb
→
actionpack/lib/action_dispatch/middleware/templates/rescues/missing_template.
html.
erb
浏览文件 @
a725a453
文件已移动
actionpack/lib/action_dispatch/middleware/templates/rescues/missing_template.text.erb
0 → 100644
浏览文件 @
a725a453
Template is missing
<%=
@exception
.
message
%>
actionpack/lib/action_dispatch/middleware/templates/rescues/routing_error.erb
→
actionpack/lib/action_dispatch/middleware/templates/rescues/routing_error.
html.
erb
浏览文件 @
a725a453
文件已移动
actionpack/lib/action_dispatch/middleware/templates/rescues/routing_error.text.erb
0 → 100644
浏览文件 @
a725a453
Routing Error
<%=
@exception
.
message
%>
<%
unless
@exception
.
failures
.
empty?
%>
Failure reasons:
<%
@exception
.
failures
.
each
do
|
route
,
reason
|
%>
-
<%=
route
.
inspect
.
delete
(
'\\'
)
%>
</code>
failed because
<%=
reason
.
downcase
%>
<%
end
%>
<%
end
%>
<%=
render
template:
"rescues/_trace"
,
format: :text
%>
actionpack/lib/action_dispatch/middleware/templates/rescues/template_error.erb
→
actionpack/lib/action_dispatch/middleware/templates/rescues/template_error.
html.
erb
浏览文件 @
a725a453
文件已移动
actionpack/lib/action_dispatch/middleware/templates/rescues/template_error.text.erb
0 → 100644
浏览文件 @
a725a453
<%
@source_extract
=
@exception
.
source_extract
(
0
,
:html
)
%>
<%=
@exception
.
original_exception
.
class
.
to_s
%>
in
<%=
@request
.
parameters
[
"controller"
].
camelize
if
@request
.
parameters
[
"controller"
]
%>
#
<%=
@request
.
parameters
[
"action"
]
%>
Showing
<%=
@exception
.
file_name
%>
where line #
<%=
@exception
.
line_number
%>
raised:
<%=
@exception
.
message
%>
<%=
@exception
.
sub_template_message
%>
<%=
render
template:
"rescues/_trace"
,
format: :text
%>
<%=
render
template:
"rescues/_request_and_response"
,
format: :text
%>
actionpack/lib/action_dispatch/middleware/templates/rescues/unknown_action.erb
→
actionpack/lib/action_dispatch/middleware/templates/rescues/unknown_action.
html.
erb
浏览文件 @
a725a453
文件已移动
actionpack/lib/action_dispatch/middleware/templates/rescues/unknown_action.text.erb
0 → 100644
浏览文件 @
a725a453
Unknown action
<%=
@exception
.
message
%>
actionpack/test/dispatch/debug_exceptions_test.rb
浏览文件 @
a725a453
...
...
@@ -128,6 +128,47 @@ def setup
assert_match
(
/ActionController::ParameterMissing/
,
body
)
end
test
"rescue with text error for xhr request"
do
@app
=
DevelopmentApp
xhr_request_env
=
{
'action_dispatch.show_exceptions'
=>
true
,
'HTTP_X_REQUESTED_WITH'
=>
'XMLHttpRequest'
}
get
"/"
,
{},
xhr_request_env
assert_response
500
assert_no_match
(
/<body>/
,
body
)
assert_equal
response
.
content_type
,
"text/plain"
assert_match
(
/puke/
,
body
)
get
"/not_found"
,
{},
xhr_request_env
assert_response
404
assert_no_match
(
/<body>/
,
body
)
assert_equal
response
.
content_type
,
"text/plain"
assert_match
(
/
#{
AbstractController
::
ActionNotFound
.
name
}
/
,
body
)
get
"/method_not_allowed"
,
{},
xhr_request_env
assert_response
405
assert_no_match
(
/<body>/
,
body
)
assert_equal
response
.
content_type
,
"text/plain"
assert_match
(
/ActionController::MethodNotAllowed/
,
body
)
get
"/unknown_http_method"
,
{},
xhr_request_env
assert_response
405
assert_no_match
(
/<body>/
,
body
)
assert_equal
response
.
content_type
,
"text/plain"
assert_match
(
/ActionController::UnknownHttpMethod/
,
body
)
get
"/bad_request"
,
{},
xhr_request_env
assert_response
400
assert_no_match
(
/<body>/
,
body
)
assert_equal
response
.
content_type
,
"text/plain"
assert_match
(
/ActionController::BadRequest/
,
body
)
get
"/parameter_missing"
,
{},
xhr_request_env
assert_response
400
assert_no_match
(
/<body>/
,
body
)
assert_equal
response
.
content_type
,
"text/plain"
assert_match
(
/ActionController::ParameterMissing/
,
body
)
end
test
"does not show filtered parameters"
do
@app
=
DevelopmentApp
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录