When I write ruby or (rails), where should I write begin
and rescue about http request (or just in general, where to write begin rescue)?
I'm talking about controller, model or module.
For example, I wrote codes like this.
module
module WhateverModule
def get_list
http, uri_path, headers = set_request("whatever_api_url")
http.get(uri_path, headers)
end
#codes continue below
end
then, I often time puts begin and rescue code at controller.
controller
begin
api_list = get_list
rescue => exception
# do whatever I need to do to handle exceptions
p "exception happened!"
end
but my PR reviewer keep saying "you should write a code like this"
module
module WhateverModule
def get_list
http, uri_path, headers = set_request("whatever_api_url")
begin
http.get(uri_path, headers)
rescue => exception
p "exception happend!"
end
end
#codes continue below
end
My question is, which one is right (or clean or better)?
Are there any general consensuses about where to put begin and rescue?
Thanks