Ruby on Rails Wednesday, June 29, 2016

A communication with API server made with JSON.
In case of application error instead of crashing with status 500 with HTML response I'd like that API clients will receive response with generic error message
{status: "Error", message: "API server error"}
or may be something more specific in some cases.

Of course, any application error should be reported to developer via Airbrake or similar gem:

Just for sake of clarity here is excerpt of that Airbrake suggests:

begin    params = {       # params that you pass to a method that can throw an exception    }    my_unpredicable_method(params)  rescue => e    Airbrake.notify_or_ignore(     e,     parameters: params,     cgi_data: ENV.to_hash    )  end

In code above they assume that application catches every descendant of StandardError. Is that good or bad practice?

On Wednesday, June 29, 2016 at 4:16:40 AM UTC+3, radhames brito wrote:
This is actually a very bad practice, you are actually creating a black hole that will swallow many relevant problems and will be super hard to debug and maintain in the future. What you want to do is only catch error that you can handle, do not catch everything, you actually have to let most raise and have 2 things: 1) generic message for the users and 2) errors notification system that will send technical details to you and your team, have a look at https://github.com/airbrake/airbrake and get documentation about it. If you want more help, please be more specific about what you want to achieve.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/53cd1e48-6e5e-4408-8476-6039ebaa5bc7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment