Coder Social home page Coder Social logo

Comments (11)

jbandhauer avatar jbandhauer commented on July 26, 2024 1

I fully agree that better docs would be great. Lacking that... 2xx responses simply return results, Other stuff throws exceptions as per the mapping in https://github.com/looker/looker-sdk-ruby/blob/master/lib/looker-sdk/error.rb#L14-L29

from looker-sdk-ruby.

drstrangelooker avatar drstrangelooker commented on July 26, 2024 1

If you look at https://github.com/looker/looker-sdk-ruby/blob/master/lib/looker-sdk/error.rb you’ll see the various errors you can catch.

LookerSDK::Error catches any 4xx or 5xx return.
LookerSDK:ClientError catches any 4xx return.
LookerSDK:ServerError catches any 5xx return.
LookerSDK::NotFound for example, catches a 404. You’ll need to look at that file to see all the other specific error classes.

So typically you might want to do something like...

begin
  # API code here
rescue LookerSDK::NotFound => e
  # handling for not found
  # This may not even be a real error case
rescue LookerSDK::ClientError => e
  # handling for any other client error
  # you can probably log a useful message
rescue LookerSDK::Error => e
  # hopefully should never get here, probably can’t recover
  # provide lots of logging and a stack trace
end

from looker-sdk-ruby.

jbandhauer avatar jbandhauer commented on July 26, 2024

I'd also recommend adding puts e.class. Often without that context the message can be confusing.

from looker-sdk-ruby.

jbandhauer avatar jbandhauer commented on July 26, 2024

... and some generic info that an exception was raised calling whatever can be helpful if you use something like this as boilerplate around other calls. Otherwise it is just printing some stuff having to do with who-knows-what.

from looker-sdk-ruby.

drstrangelooker avatar drstrangelooker commented on July 26, 2024

For the short examples like this, the raise makes sure that the call stack is printed so the developer can have a clue of what is happening where. For a more fully fledged application, absolutely.

from looker-sdk-ruby.

jbandhauer avatar jbandhauer commented on July 26, 2024

OK, sure. But, you didn't show something that is necessarily a full program; you showed a snippet, so no telling what code is gonna eat the exception if someone integrates that into their larger program. Just say'n ;)

from looker-sdk-ruby.

jakemitchellxyz avatar jakemitchellxyz commented on July 26, 2024

+1 - I still have no clue how to catch errors with the SDK (aside from the generic catch above). It should be very clear in the readme or in the Docs or API reference (or all 3) how to check the status of an API call from the SDK. For my use case, I just need to know whether the call returned 200 or something else, but I don't know how to do that without looking at the SDK code. If I wanted to handle 409 in a special way, I (as a user) don't know how to check that.

from looker-sdk-ruby.

jbandhauer avatar jbandhauer commented on July 26, 2024

I suspect that for most SDK use cases one wants to assume success and just report the errors (and fail) and not be highly concerned about specially processing specific error types - unless you are really writing something that knows exactly how to logically handle them and can work around any failures. That is why they are modeled as exceptions and not as a pattern that requires explicit checking of result code after each API call. Pardon the pun, but I think scripts that really know how to handle such errors without simply failing are the exceptional case.

from looker-sdk-ruby.

jakemitchellxyz avatar jakemitchellxyz commented on July 26, 2024

That's great! Yeah, I saw that file, but people using the SDK shouldn't have to read the code to see how to handle errors. The use case @deangelo-llooker just showed is fantastic, I think that should go in the docs or somewhere more visible. I agree the exhaustive list of classes can stay hiding in the code though, like you said, I don't think many people will need to use that very often

from looker-sdk-ruby.

drstrangelooker avatar drstrangelooker commented on July 26, 2024

from looker-sdk-ruby.

jakemitchellxyz avatar jakemitchellxyz commented on July 26, 2024

Also for context, in my use case, if I get a LookerSDK::Conflict, I can just pretend nothing happened, but any other error I need to log and fail

from looker-sdk-ruby.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.