@@ -19,11 +19,11 @@ def default_options
19
19
rescue_subclasses : true , # rescue subclasses of exceptions listed
20
20
rescue_options : {
21
21
backtrace : false , # true to display backtrace, true to let Grape handle Grape::Exceptions
22
- original_exception : false , # true to display exception
22
+ original_exception : false # true to display exception
23
23
} ,
24
24
rescue_handlers : { } , # rescue handler blocks
25
25
base_only_rescue_handlers : { } , # rescue handler blocks rescuing only the base class
26
- all_rescue_handler : nil , # rescue handler block to rescue from all exceptions
26
+ all_rescue_handler : nil # rescue handler block to rescue from all exceptions
27
27
}
28
28
end
29
29
@@ -38,15 +38,15 @@ def call!(env)
38
38
error_response ( catch ( :error ) do
39
39
return @app . call ( @env )
40
40
end )
41
- rescue Exception => error # rubocop:disable Lint/RescueException
41
+ rescue Exception => e # rubocop:disable Lint/RescueException
42
42
handler =
43
- rescue_handler_for_base_only_class ( error . class ) ||
44
- rescue_handler_for_class_or_its_ancestor ( error . class ) ||
45
- rescue_handler_for_grape_exception ( error . class ) ||
46
- rescue_handler_for_any_class ( error . class ) ||
43
+ rescue_handler_for_base_only_class ( e . class ) ||
44
+ rescue_handler_for_class_or_its_ancestor ( e . class ) ||
45
+ rescue_handler_for_grape_exception ( e . class ) ||
46
+ rescue_handler_for_any_class ( e . class ) ||
47
47
raise
48
48
49
- run_rescue_handler ( handler , error )
49
+ run_rescue_handler ( handler , e )
50
50
end
51
51
end
52
52
@@ -65,15 +65,13 @@ def error_response(error = {})
65
65
message = error [ :message ] || options [ :default_message ]
66
66
headers = { Grape ::Http ::Headers ::CONTENT_TYPE => content_type }
67
67
headers . merge! ( error [ :headers ] ) if error [ :headers ] . is_a? ( Hash )
68
- backtrace = error [ :backtrace ] || error [ :original_exception ] && error [ :original_exception ] . backtrace || [ ]
68
+ backtrace = error [ :backtrace ] || error [ :original_exception ] & .backtrace || [ ]
69
69
original_exception = error . is_a? ( Exception ) ? error : error [ :original_exception ] || nil
70
70
rack_response ( format_message ( message , backtrace , original_exception ) , status , headers )
71
71
end
72
72
73
73
def rack_response ( message , status = options [ :default_status ] , headers = { Grape ::Http ::Headers ::CONTENT_TYPE => content_type } )
74
- if headers [ Grape ::Http ::Headers ::CONTENT_TYPE ] == TEXT_HTML
75
- message = ERB ::Util . html_escape ( message )
76
- end
74
+ message = ERB ::Util . html_escape ( message ) if headers [ Grape ::Http ::Headers ::CONTENT_TYPE ] == TEXT_HTML
77
75
Rack ::Response . new ( [ message ] , status , headers )
78
76
end
79
77
0 commit comments