Comments (11)
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.
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.
I'd also recommend adding puts e.class
. Often without that context the message can be confusing.
from looker-sdk-ruby.
... 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.
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.
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.
+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.
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.
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.
from looker-sdk-ruby.
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)
- post/put/patch methods must specify all headers if present in options passed to method
- Login endpoint appears to be incorrect in the authentication.md file
- Dependency problem with faraday 1.0.0 HOT 3
- travis doesn't seem to work right for pull requests here
- Conversion of "date like" string data to datetime is too aggressive
- Exception thrown when calling #alive HOT 2
- Consider an option to bypass/replace Sawyer
- How do I convert my Rest webservice spring mvc application from swagger 1.0 to swagger 2.0. HOT 1
- Missing tags for looker-sdk HOT 1
- Sawyer version HOT 1
- Consider getting rid of the client CONVENIENCE_HEADERS handling
- Option to includes roles for user(user_id) and all_users? HOT 1
- Release new version of the gem HOT 4
- Reduce output volume of sdk.inspect HOT 1
- Faraday dependency makes the SDK incompatible with gems HOT 3
- Undefined method look or run_look for Looker::Client HOT 1
- v0.0.6 doesn't work on Ruby 1.9.3
- NoMethodError for LookerSDK::Client HOT 9
- api key and secret should be sent via body, not query string HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from looker-sdk-ruby.