Rails External Service Exception Handling -
i connecting application third party api pull , push data. 1 thing i'd implement exception handling users receive related error message if happens api.
i have show action has main call third party service inside. i've wrapped service in begin rescue block. i'm receiving following error:
render and/or redirect called multiple times in action. my show action looks this
def show begin client = foobarrest::client.new [api request code here] rescue => e rails.logger.error { "#{e.message} #{e.backtrace.join("\n")}" } redirect_to signing_error_path end render_wizard end i understand have 2 renders/redirects (the render_wizard there satisfy wizard's requirements) happening in block- i'm unsure how redirect signing_error_path other way.
i have errors controller , views built handle 404s, 500s etc:class
errorscontroller < applicationcontroller def not_found end def unavailable end def internal_error end def unauthorized_access end def signing_error end end the corresponding views in views/errors folder. how can display signing_error view if exception raised current show method?
you can use code as-is if add and return on redirect_to line
if need redirect on condition of something, sure add “and return” halt execution.
alternatively, place render_wizard call inside begin block, right before rescue => e line
Comments
Post a Comment