[katello-devel] Introducing ApiError in the ApiController

Dmitri Dolguikh dmitri at redhat.com
Thu Jul 28 10:40:22 UTC 2011


On 11-07-28 6:12 AM, Lukas Zapletal wrote:
> Hello,
>
> while I was tracing one issue in our API controllers I have found we 
> are throwing away original exceptions. Example:
>
> def import_manifest
>   # ....
>   # ....
>   # ....
>   rescue => e
>     raise _("Manifest import failed")
> end
>
> The problem with the code above is we are loosing the original 
> exception and I have to either insert some tracing statements or dig 
> in the backend engine logs to find out what's wrong.
>
> I have introduced new class ApiError and new handler in the 
> ApiController that prints the message, original error message and 
> original error backtrace. It also returns both messages (but not 
> backtrace) to the client.
>
> class ApiError < StandardError
>   attr_reader :original
>
>   def initialize(msg, original=$!)
>     super(msg)
>     @original = original
>   end
> end
>
> rescue_from ApiError, :with => proc { |e| render_api_exception(500, e) }
>
> The only change we need to do is to raise this type instead of the 
> original type. It will accept the user-friendly message and the second 
> parameter is optional (default = last exception thrown).
>
> def import_manifest
>   # ....
>   # ....
>   # ....
>   rescue => e
>     raise ApiError, _("Manifest import failed")
> end
>
> That's all. If there are no objections I will update all the places.
>
definitely a good idea, Lukas.
-d
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/katello-devel/attachments/20110728/74be0f24/attachment.htm>


More information about the katello-devel mailing list