Method: HaveAPI::Action#safe_exec
- Defined in:
- lib/haveapi/action.rb
#safe_exec ⇒ Object
Calls exec while catching all exceptions and restricting output only to what user can see. Return array [status, data|error, errors]
363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 |
# File 'lib/haveapi/action.rb', line 363 def safe_exec exec_ret = catch(:return) do validate! prepare pre_exec exec rescue Exception => e # rubocop:disable Lint/RescueException tmp = call_class_hooks_as_for(Action, :exec_exception, args: [@context, e]) if tmp.empty? p e. puts e.backtrace error!('Server error occurred') end unless tmp[:status] error!(tmp[:message], {}, http_status: tmp[:http_status] || 500) end end begin output_ret = safe_output(exec_ret) rescue Exception => e # rubocop:disable Lint/RescueException tmp = call_class_hooks_as_for(Action, :exec_exception, args: [@context, e]) p e. puts e.backtrace return [ tmp[:status] || false, tmp[:message] || 'Server error occurred', {}, tmp[:http_status] || 500 ] end output_ret end |