On Fri, Feb 10, 2012 at 5:14 PM, tan yeun <tayetemp / gmail.com> wrote:
> Hi friends,
>
> I am developing a ruby software that depends on api from the other team
>
> Is there any good way to print the error message indicating it is
> generated from their api error?
>
> For example, there's a method provided from the api called foo()
>
> so when I do
> api.foo()
> it will return an error message : "foo error"
>
> when I develop my code, I want the error message to look like :
> "api: foo error"
>
> that way, when I see this error message, then I know it's the api error,
> not my code's error.
>
> So far the best practice I can think of is to wrap around all the
> methods
> provided by the api, for example
>
> class apiWrap

Your class name should be a constant =3D> Start with an uppercase character=
.

> =A0def initialize(api)
> =A0 =A0@api =3D api
> =A0end
> =A0def foo
> =A0 =A0begin
> =A0 =A0 =A0 / api.foo()
> =A0 =A0rescue =3D> e
> =A0 =A0 =A0raise "api: #{e.message}"
> =A0 =A0end
> =A0end
> end
>
> any ideas?

Remove the begin rescue end. Seriously: if you cannot handle the error
by throwing another error or doing something else just le the original
exception pass.

Kind regards

robert

--=20
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/